configuration page. Bug reports and feature requests welcome! License: GPL */ // Include PDF/PDI functions (have a look at http://www.fpdf.org - nice library and freeware!) define( 'FPDF_FONTPATH', dirname(__FILE__) . "/contributed/pdffonts/" ); define( 'FPDF_TEMPLATEPATH', dirname(__FILE__) . "/contributed/pdftemplates/" ); define( 'FPDF_INCLUDEPATH', dirname(__FILE__) . "/contributed/fpdf/" ); define( 'FPDI_INCLUDEPATH', dirname(__FILE__) . "/contributed/fpdi/" ); define( 'A2P_CACHEPATH', dirname(__FILE__) . "/../../uploads/" ); require_once( FPDF_INCLUDEPATH . 'fpdf.php' ); require_once( FPDI_INCLUDEPATH . 'fpdi.php' ); // The main plugin class class article2pdf { var $a2p_AdminOptionsName; var $s2p_AdminOptions; // Construct function __construct() { $this -> a2p_AdminOptionsName = 'a2pPlugin_AdminOptions'; $this -> a2p_AdminOptions = $this -> a2p_GetAdminOptions(); } // PHP4 compatibe construct (please update to PHP 5 soon! ;) ) function article2pdf() { $this -> __construct(); } // Get options for this plugin function a2p_GetAdminOptions() { // Set default options $a2pOptions = array( 'PDFTemplateFile' => '', 'PDFTemplateMarginLeft' => 25, 'PDFTemplateMarginRight' => 25, 'PDFTemplateMarginTop' => 25, 'PDFTemplateMarginBottom' => 25, 'PDFOptionIncludePics' => 'true', 'PDFOptionIncludeDate' => 'true', 'PDFOptionDateformat' => '%x -', 'PDFOptionDateLocale' => 'en_EN', 'PDFOptionFont' => 'Arial', 'PDFOptionFontSize' => 12, 'PDFOptionLineHeight' => 6, 'PDFOptionCacheTime' => 3600 ); // Load existing options $_a2pOptions = get_option( $this -> a2p_AdminOptionsName ); // Overwrite defaults if( count( $_a2pOptions ) ) { foreach( $_a2pOptions AS $oKey => $oVal ) { $a2pOptions[ $oKey ] = $oVal; } } // Set default options to wp db if no existing options or new options are found if( !count( $_a2pOptions ) || count( $_a2pOptions ) != count( $a2pOptions ) ) { update_option( $this -> a2p_AdminOptionsName, $a2pOptions ); } // Return options return $a2pOptions; } // Create pdf function a2p_CreatePdf() { // Get post global $post; // Set base url $base_url = ($_SERVER[ "HTTPS" ] ? "https" : "http") . "://" . $_SERVER[ "HTTP_HOST" ] . "/"; if( !empty( $post -> ID ) ) { // Get File from cache? $cachefile = $this -> _cache_get_filename( $post ); if( $this -> _cache_recreate( $cachefile ) ) { $pdf =& new FPDI(); $pdf -> SetAuthor( "WordPress article2pdf plugin" ); $pdf -> SetCreator( "WordPress article2pdf plugin" ); $pdf -> SetTitle( utf8_decode( strip_tags( $post -> post_title ) ) ); if( !empty( $this -> a2p_AdminOptions[ 'PDFTemplateFile' ] ) ) { $pdf -> setSourceFile( FPDF_TEMPLATEPATH . $this -> a2p_AdminOptions[ 'PDFTemplateFile' ] ); $pdf -> tplIdx = $pdf -> importPage( 1 ); } $pdf -> SetLineWidth( 0.2 ); $pdf -> AddPage(); if( !empty( $this -> a2p_AdminOptions[ 'PDFTemplateFile' ] ) ) $pdf -> useTemplate( $pdf -> tplIdx ); $pdf -> SetLeftMargin( $this -> a2p_AdminOptions[ 'PDFTemplateMarginLeft' ] ); $pdf -> SetRightMargin( $this -> a2p_AdminOptions[ 'PDFTemplateMarginRight' ] ); $pdf -> SetTopMargin( $this -> a2p_AdminOptions[ 'PDFTemplateMarginTop' ] ); $pdf -> SetAutoPageBreak( true, $this -> a2p_AdminOptions[ 'PDFTemplateMarginBottom' ] ); $pdf -> SetXY( $this -> a2p_AdminOptions[ 'PDFTemplateMarginLeft' ], $this -> a2p_AdminOptions[ 'PDFTemplateMarginRight' ] ); // Write title if( $this -> a2p_AdminOptions[ 'PDFOptionIncludeDate' ] == 'true' ) { $date_timestamp = strtotime( $post -> post_date ); setlocale( LC_TIME, $this -> a2p_AdminOptions[ 'PDFOptionDateLocale' ] . '.UTF8' ); $date_str = strftime( $this -> a2p_AdminOptions[ 'PDFOptionDateformat' ], $date_timestamp ); $post -> post_title = $date_str . ' ' . $post -> post_title; } $this -> _font_bold( $pdf ); $pdf -> Cell( 0, $this -> a2p_AdminOptions[ 'PDFOptionLineHeight' ] * ceil( $pdf -> GetStringWidth( html_entity_decode( utf8_decode( strip_tags( $post -> post_title ) ) ) ) / ($pdf -> w - $pdf -> lMargin - $pdf -> rMargin) ), html_entity_decode( utf8_decode( strip_tags( $post -> post_title ) ) ), 1, 1, 'C' ); $this -> _font_normal( $pdf ); $pdf -> Ln(); // Write body $pdf -> SetFont( $this -> a2p_AdminOptions[ 'PDFOptionFont' ], '', $this -> a2p_AdminOptions[ 'PDFOptionFontSize' ] ); // Prepare tables to be in a single paragraph (easier to parse) preg_match_all( '#.*(.*).*#siU', $post -> post_content, $tables ); if( count( $tables[ 1 ] ) ) { foreach( $tables[ 1 ] AS $tkey => $tbl ) { $tbl = str_replace( array( "\n", "\r" ), '', $tbl ); $post -> post_content = str_replace( $tables[ 1 ][ $tkey ], $tbl, $post -> post_content ); } } // Explore by paragraph $paragraphs_array = explode( "\n", $post -> post_content ); $isFirstParagraph = true; $link_href = ''; foreach( $paragraphs_array AS $pkey => $p ) { $page_before = $pdf -> PageNo(); $p = trim( $p ); if( !empty( $p ) ) { // Convert tables $p = $this -> _convert_tables( $p ); // Convert links $p = $this -> _convert_links( $p ); // Convert bold $p = $this -> _convert_bold( $p ); // Convert underline $p = $this -> _convert_underline( $p ); // Convert italic $p = $this -> _convert_italic( $p ); // Convert blockquote $p = $this -> _convert_blockquote( $p ); // Convert lists and items $p = $this -> _convert_listitem( $p ); // Convert headings $p = $this -> _convert_heading( $p ); // Convert horizontal lines $p = $this -> _convert_lines( $p ); // Write text $breaks_after = 2; $parts = explode( '|-====-|', $p ); foreach( $parts AS $pkey => $part ) { // Parse style of part // ...beginnings if( substr( $part, 0, 5 ) == 'LINK|' ) { $this -> _font_underline( $pdf ); $part = substr( $part, 5 ); $part_arr = explode( '|', $part ); $link_href = $part_arr[ 0 ]; unset( $part_arr[ 0 ] ); $part = implode( $part_arr ); unset( $part_arr ); } if( substr( $part, 0, 2 ) == 'U|' ) { $this -> _font_underline( $pdf ); $part = substr( $part, 2 ); } if( substr( $part, 0, 2 ) == 'B|' ) { $this -> _font_bold( $pdf ); $part = substr( $part, 2 ); } if( substr( $part, 0, 2 ) == 'I|' ) { $this -> _font_italic( $pdf ); $part = substr( $part, 2 ); } if( substr( $part, 0, 1 ) == 'H' && substr( $part, 2, 1 ) == '|' ) { $hlevel = substr( $part, 1, 1 ); $this -> _font_heading( $pdf, $hlevel ); $part = substr( $part, 3 ); } if( substr( $part, 0, 2 ) == 'Q|' ) { $this -> _margin_quote( $pdf ); $part = substr( $part, 2 ); } if( substr( $part, 0, 3 ) == 'UL|' || substr( $part, 0, 3 ) == 'OL|' ) { $this -> _margin_quote( $pdf ); $part = substr( $part, 3 ); $breaks_after = 1; } if( substr( $part, 0, 3 ) == 'LI|' ) { $part = substr( $part, 3 ); $part = '• ' . $part; } if( substr( $part, 0, 3 ) == 'TR|' ) { if( !isset( $trheight ) ) { $trheight = $this -> a2p_AdminOptions[ 'PDFOptionLineHeight' ]; $pdf -> SetX( $this -> a2p_AdminOptions[ 'PDFTemplateMarginLeft' ] ); } else { $pdf -> SetXY( $this -> a2p_AdminOptions[ 'PDFTemplateMarginLeft' ], $y + $trheight ); $trheight = $this -> a2p_AdminOptions[ 'PDFOptionLineHeight' ]; } $ccount = intval( substr( $part, 3 ) ); $cwidth = floor( ($pdf -> w - $pdf -> lMargin - $pdf -> rMargin) / $ccount ); $part = ''; $tdcounter = 1; } if( substr( $part, 0, 3 ) == 'TH|' ) { $this -> _font_bold( $pdf ); $cpart = html_entity_decode( utf8_decode( strip_tags( trim( substr( $part, 3 ) ) ) ) ); $pdf -> SetFillColor( 0xCC, 0xCC, 0xCC ); $y = $pdf -> GetY(); $x = $pdf -> GetX(); $pdf -> MultiCell( $cwidth, $this -> a2p_AdminOptions[ 'PDFOptionLineHeight' ], $cpart, 'LTR', 'C', true ); if( $pdf -> GetY() < $y ) { $pdf -> useTemplate( $pdf -> tplIdx ); $trheight = $pdf -> GetY() - $this -> a2p_AdminOptions[ 'PDFTemplateMarginTop' ]; $pdf -> SetXY( $x + $cwidth, $this -> a2p_AdminOptions[ 'PDFTemplateMarginTop' ] ); } else { $trheight = (($pdf -> GetY() - $y) > $trheight ? $pdf -> GetY() - $y : $trheight); if( $tdcounter == $ccount ) { for( $lc = 0; $lc <= $ccount; $lc++ ) $pdf -> Line( $this -> a2p_AdminOptions[ 'PDFTemplateMarginLeft' ] + ($cwidth * $lc), $y, $this -> a2p_AdminOptions[ 'PDFTemplateMarginLeft' ] + ($cwidth * $lc), $y + $trheight ); } $pdf -> SetXY( $x + $cwidth, $y ); } $part = ''; $tdcounter++; } if( substr( $part, 0, 3 ) == 'TD|' ) { $pdf -> SetFontSize( floor( $this -> a2p_AdminOptions[ 'PDFOptionFontSize' ] * 0.80 ) ); $cpart = html_entity_decode( utf8_decode( strip_tags( trim( substr( $part, 3 ) ) ) ) ); $y = $pdf -> GetY(); $x = $pdf -> GetX(); $pdf -> MultiCell( $cwidth, $this -> a2p_AdminOptions[ 'PDFOptionLineHeight' ], $cpart, 'LTR', 'L', false ); if( $pdf -> GetY() < $y ) { $pdf -> useTemplate( $pdf -> tplIdx ); $trheight = $pdf -> GetY() - $this -> a2p_AdminOptions[ 'PDFTemplateMarginTop' ]; $pdf -> SetXY( $x + $cwidth, $this -> a2p_AdminOptions[ 'PDFTemplateMarginTop' ] ); $y = $this -> a2p_AdminOptions[ 'PDFTemplateMarginTop' ]; } else { $trheight = (($pdf -> GetY() - $y) > $trheight ? $pdf -> GetY() - $y : $trheight); if( $tdcounter == $ccount ) { for( $lc = 0; $lc <= $ccount; $lc++ ) $pdf -> Line( $this -> a2p_AdminOptions[ 'PDFTemplateMarginLeft' ] + ($cwidth * $lc), $y, $this -> a2p_AdminOptions[ 'PDFTemplateMarginLeft' ] + ($cwidth * $lc), $y + $trheight ); } $pdf -> SetXY( $x + $cwidth, $y ); } $part = ''; $tdcounter++; $pdf -> SetFontSize( $this -> a2p_AdminOptions[ 'PDFOptionFontSize' ] ); } if( substr( $part, 0, 3 ) == '__|' ) { $part = ''; $y = $pdf -> GetY(); $pdf -> SetLineWidth( 0.4 ); $pdf -> Line( $this -> a2p_AdminOptions[ 'PDFTemplateMarginLeft' ], $y, $pdf -> w - $this -> a2p_AdminOptions[ 'PDFTemplateMarginRight' ], $y ); $pdf -> SetLineWidth( 0.2 ); $breaks_after = 1; } // Get Images from text if( $this -> a2p_AdminOptions[ 'PDFOptionIncludePics' ] == 'true' ) { if( preg_match_all( '##iU', $part, $matches ) ) { foreach( $matches[ 1 ] AS $ikey => $img ) { // Convert to local img path, if current base url found in img src if( strpos( $img, $base_url ) === 0 ) $img = $_SERVER[ 'DOCUMENT_ROOT' ] . (substr( $_SERVER[ 'DOCUMENT_ROOT' ], -1 ) != '/' ? '/' : '') . str_replace( $base_url, '', $img ); // Get dimensions $imgsize = GetImageSize( $img ); // Set size to points at 72 dpi $imgsize[ 0 ] = $imgsize[ 0 ] / $pdf -> k; $imgsize[ 1 ] = $imgsize[ 1 ] / $pdf -> k; // Begin new page if image has too much height if( $isFirstParagraph == false ) { if( ($pdf -> GetY() + $imgsize[ 1 ]) > ($pdf -> h - $pdf -> bMargin) ) { $pdf -> AddPage(); $pdf -> SetXY( $this -> a2p_AdminOptions[ 'PDFTemplateMarginLeft' ], $this -> a2p_AdminOptions[ 'PDFTemplateMarginRight' ] ); } } // Centered image $pdf -> Image( $img, ($pdf -> w / 2) - ($imgsize[ 0 ] / 2), $pdf -> GetY(), 0, 0, '', $link_href ); // Set next X,Y position of following text $pdf -> SetXY( $this -> a2p_AdminOptions[ 'PDFTemplateMarginLeft' ], $pdf -> GetY() + $imgsize[ 1 ] + $this -> a2p_AdminOptions[ 'PDFOptionLineHeight' ] ); // Remove img from paragraph $part = str_replace( $matches[ 0 ][ $ikey ], '', $part ); } $breaks_after = 0; } } // ...endings if( substr( $part, 0, 3 ) == '/U|' || substr( $part, 0, 3 ) == '/B|' || substr( $part, 0, 3 ) == '/I|' ) { $this -> _font_normal( $pdf ); $part = substr( $part, 3 ); } if( substr( $part, 0, 6 ) == '/LINK|' ) { $this -> _font_normal( $pdf ); $part = substr( $part, 6 ); $link_href = ''; } if( substr( $part, 0, 4 ) == '/UL|' || substr( $part, 0, 4 ) == '/OL|' ) { $this -> _margin_normal( $pdf ); $part = substr( $part, 4 ); $breaks_after = 2; } if( substr( $part, 0, 4 ) == '/LI|' ) { $part = substr( $part, 4 ); $breaks_after = 1; } if( substr( $part, 0, 2 ) == '/H' ) { $this -> _font_normal( $pdf ); $part = substr( $part, 4 ); $breaks_after = 2; } if( substr( $part, 0, 4 ) == '/TD|' || substr( $part, 0, 4 ) == '/TH|' || substr( $part, 0, 4 ) == '/TR|' ) { if( substr( $part, 0, 4 ) == '/TR|' ) $pdf -> Line( $this -> a2p_AdminOptions[ 'PDFTemplateMarginLeft' ], $y + $trheight, $pdf -> w - $this -> a2p_AdminOptions[ 'PDFTemplateMarginRight' ], $y + $trheight ); $this -> _font_normal( $pdf ); $part = substr( $part, 4 ); } if( substr( $part, 0, 3 ) == '/Q|' ) { $this -> _margin_normal( $pdf ); $part = substr( $part, 3 ); } // Write part $part_content = html_entity_decode( utf8_decode( strip_tags( $part ) ) ); if( !empty( $part_content ) ) $pdf -> Write( $this -> a2p_AdminOptions[ 'PDFOptionLineHeight' ], $part_content, $link_href ); } // Begin new paragraph for( $b = 0; $b < $breaks_after; $b++ ) $pdf -> Write( $this -> a2p_AdminOptions[ 'PDFOptionLineHeight' ], "\n" ); // Set first paragraph is printed $isFirstParagraph = false; } // On page break use pdf template if( $page_before != $pdf -> PageNo() && !empty( $this -> a2p_AdminOptions[ 'PDFTemplateFile' ] ) ) $pdf -> useTemplate( $pdf -> tplIdx ); } // Output pdf to disk or direct to browser header( "Content-Type: application/pdf" ); header( "Content-Disposition: attachment; filename=\"" . $post -> post_name . ".pdf\"" ); if( !empty( $this -> a2p_AdminOptions[ 'PDFOptionCacheTime' ] ) ) { $pdf -> Output( $cachefile, 'F' ); echo file_get_contents( $cachefile ); } else echo $pdf -> Output( '', 'S' ); die(); } else { // Output pdf from disk header( "Content-Type: application/pdf" ); header( "Content-Disposition: attachment; filename=\"" . $post -> post_name . ".pdf\"" ); echo file_get_contents( $cachefile ); die(); } } } // Adminpage function a2p_AdminPage() { if( function_exists( 'load_plugin_textdomain' ) ) { load_plugin_textdomain( 'article2pdf', 'wp-content/plugins/article2pdf' ); } $open = 0; // Delete cache if( $_POST[ 'a2p_admin_action' ] == 'cache_delete' ) { if( $d = opendir( A2P_CACHEPATH ) ) { while( false !== ($cf = readdir( $d ) ) ) { $fSuffix_Arr = explode( ".", $cf ); if( end( $fSuffix_Arr ) == 'pdf' && $fSuffix_Arr[ 0 ] == 'a2p' && $fSuffix_Arr[ 1 ] == 'cache' ) { unlink( A2P_CACHEPATH . $cf ); } } } print "

" . __( "All cache files deleted.", "article2pdf" ) . "

"; $open = 4; } // Delete action if( $_POST[ 'a2p_admin_action' ] == 'delete' ) { if( !empty( $_POST[ 'PDFTemplateFile' ] ) ) { if( $_POST[ 'PDFTemplateFile' ] != $this -> a2p_AdminOptions[ 'PDFTemplateFile' ] ) { if( unlink( FPDF_TEMPLATEPATH . $_POST[ 'PDFTemplateFile' ] ) ) { print "

" . __( "The file was successfully deleted.", "article2pdf" ) . "

"; } else { print "

" . __( "Sorry, the deletion of the file failed. Maybe the directory is not writeable from the webserver?", "article2pdf" ) . "

"; } } else { print "

" . __( "Sorry, we can't delete the file that is currently set as template file.", "article2pdf" ) . "

"; } } else { print "

" . __( "No file selected, no file deleted. That was easy...", "article2pdf" ) . "

"; } $open = 3; } // Upload action if( $_POST[ 'a2p_admin_action' ] == 'upload' ) { if( is_uploaded_file( $_FILES[ 'templatefile' ][ 'tmp_name' ] ) ) { if( is_writeable( FPDF_TEMPLATEPATH ) ) { $suffix_arr = explode( '.', $_FILES[ 'templatefile' ][ 'name' ] ); if( strtolower( end( $suffix_arr ) ) == 'pdf' ) { $local_filename = preg_replace( '/[^a-z0-9\.]/i', '', $_FILES[ 'templatefile' ][ 'name' ] ); if( move_uploaded_file( $_FILES[ 'templatefile' ][ 'tmp_name' ], FPDF_TEMPLATEPATH . $local_filename ) ) { print "

" . __( "Upload successful. Now you can use the pdf file as template. Just configure that in the article2pdf options.", "article2pdf" ) . "

"; $open = 1; } else { print "

" . __( "Sorry, the file could not moved to the target directory. Maybe the directory is not writeable from the webserver?", "article2pdf" ) . "

"; $open = 2; } } else { print "

" . __( "This is not a pdf file. Upload failed.", "article2pdf" ) . "

"; $open = 2; } } else { print "

" . __( "Sorry, the directory is not writeable by the webserver. Please set the correct owner.", "article2pdf" ) . "

"; $open = 2; } } else { print "

" . __( "No upload file? Sorry, dave...", "article2pdf" ) . "

"; $open = 2; } } // Store action if( $_POST[ 'a2p_admin_action' ] == 'set' ) { $a2pOptionsNew = array(); foreach( array_keys( $this -> a2p_AdminOptions ) AS $oKey ) $a2pOptionsNew[ $oKey ] = (!eregi( "[^0-9,.]", $_POST[ $oKey ] ) ? str_replace( ',', '.', $_POST[ $oKey ] ) : $_POST[ $oKey ]); update_option( $this -> a2p_AdminOptionsName, $a2pOptionsNew ); $this -> a2p_AdminOptions = $a2pOptionsNew; print "

" . __( "Options updated.", "article2pdf" ) . "

"; } // Container print "
\n"; print "

" . __( "article2pdf plugin admin page", "article2pdf" ) . "

\n"; print "
"; // Output setup form print "
\n"; print "
\n"; print "
\n"; print "\n"; print "

" . __( "article2pdf options", "article2pdf" ) . "

\n"; print "
\n"; print "

" . __( "PDF template file", "article2pdf" ) . "

"; print "\n"; print "\n"; print "
"; print __( "To use a pdf file as template for your genereated pdf files, just place the template file in /wp-content/plugins/article2pdf/contributed/pdftemplates/ and choose the file from the select box.", "article2pdf" ) . "\n"; print ""; $sTpl = "\n"; print $sTpl; print "
\n"; // PDFTemplateMarginLeft, PDFTemplateMargin... print "\n"; print "

" . __( "PDF Page Margins (unit is millimeters)", "article2pdf" ) . "

\n"; print "\n"; print "\n"; print "
"; print __( "Set your page margins here...", "article2pdf" ); print ""; print ""; print ""; print ""; print ""; print "
  a2p_AdminOptions[ 'PDFTemplateMarginTop' ] . "\"/> 
a2p_AdminOptions[ 'PDFTemplateMarginLeft' ] . "\"/>  a2p_AdminOptions[ 'PDFTemplateMarginRight' ] . "\"/>
  a2p_AdminOptions[ 'PDFTemplateMarginBottom' ] . "\"/> 
"; print "
\n"; // PDFOptionIncludePics: select true or false print "

" . __( "Include pictures into the pdf file?", "article2pdf" ) . "

"; print "\n"; print "\n"; print "
"; print __( "Set if pictures in the article should be included into the generated pdf file.", "article2pdf" ); print ""; print "\n"; print "
\n"; // PDFOptionIncludeDate: select true or false print "

" . __( "Output publication date before the post title?", "article2pdf" ) . "

"; print "\n"; print "\n"; print "
"; print __( "Set if the publication date should be printed at the beginning of the post title.", "article2pdf" ); print ""; print "\n"; print "
\n"; // PDFOptionDateformat: set date format print "

" . __( "Use date format", "article2pdf" ) . "

\n"; print "\n"; print "\n"; print "
"; print __( "Define the date format used for printing out the date. Read http://php.net/strftime if you are uncertain what to enter.", "article2pdf" ); print ""; print " a2p_AdminOptions[ 'PDFOptionDateformat' ] . "\"/> \n"; print "
\n"; // PDFOptionDateLocale: set date locale print "

" . __( "Use date locale", "article2pdf" ) . "

\n"; print "\n"; print "\n"; print "
"; print __( "Define the date format locale information, eg: de_DE for Germany, nl_NL for netherlands, en_US, for the States and so on.", "article2pdf" ); print ""; print " a2p_AdminOptions[ 'PDFOptionDateLocale' ] . "\"/> \n"; print "
\n"; // PDFOptionFont: set font to use print "

" . __( "Use font", "article2pdf" ) . "

\n"; print "\n"; print "\n"; print "
"; print __( "Define the font that is used to generate text in the pdf file, have a look to the directory /wp-content/plugins/article2pdf/contributed/pdffonts/ and find out which other fonts are available.", "article2pdf" ); print ""; print " a2p_AdminOptions[ 'PDFOptionFont' ] . "\"/> \n"; print "
\n"; // PDFOptionFontSize: set font size print "

" . __( "Use font size", "article2pdf" ) . "

\n"; print "\n"; print "\n"; print "
"; print __( "Enter the font size that should be used when writing text.", "article2pdf" ); print ""; print " a2p_AdminOptions[ 'PDFOptionFontSize' ] . "\"/> \n"; print "
\n"; // PDFOptionLineHeight: set line height print "

" . __( "Line height", "article2pdf" ) . "

\n"; print "\n"; print "\n"; print "
"; print __( "Use the given line heigth. Hint: Set it to half of the fontsize and you will get good results.", "article2pdf" ); print ""; print " a2p_AdminOptions[ 'PDFOptionLineHeight' ] . "\"/> \n"; print "
\n"; // PDFOptionCacheTime: set time to cache pdf file before recreation, or zero too turn off print "

" . __( "Cache options", "article2pdf" ) . "

\n"; print "\n"; print "\n"; print "
"; print __( "Enter the time in seconds that pdf files are delivered from cache before they are recreated. Enter 0 to deactivate caching.", "article2pdf" ); print ""; print " a2p_AdminOptions[ 'PDFOptionCacheTime' ] . "\"/>
\n"; print __( "Popular values: 3600 = 1 hour, 21600 = 6 hours, 86400 = 1 day", "article2pdf" ); print "
\n"; print "
\n"; print "\n"; print "
\n"; print "
\n"; print "
\n"; // Output template uploadform print "
\n"; print "
\n"; print "
\n"; print "\n"; print "

" . __( "Upload a new pdf template file", "article2pdf" ) . "

\n"; print "
\n"; print "

" . __( "Choose pdf template file from your local disk", "article2pdf" ) . "

"; print "\n"; print "\n"; print "
"; print ""; print "
\n"; print "

" . __( "Important: The directory /wp-content/plugins/article2pdf/contributed/pdftemplates must be writeable for your webserver, or the upload will fail. If you have problems, set the owner and group of the directory to the user and group of your webserver (chown www-user.www-group for example).", "article2pdf" ) . "

"; print "
\n"; print "\n"; print "
\n"; print "
\n"; print "
\n"; // Delete template form print "
\n"; print "
\n"; print "
\n"; print "\n"; print "

" . __( "Delete a pdf template file", "article2pdf" ) . "

\n"; print "
\n"; print "

" . __( "Choose template file and submit the form", "article2pdf" ) . "

"; print "\n"; print "\n"; print "
"; print str_replace( 'selected="selected"', '', $sTpl ); print "
\n"; print "

" . __( "Important: Do not choose the template file that is currently in use. The file will not be deleted if you do.", "article2pdf" ) . "

"; print "
\n"; print "\n"; print "
\n"; print "
\n"; print "
\n"; // Cache status print "
\n"; print "
\n"; print "
\n"; print "\n"; print "

" . __( "Cache status", "article2pdf" ) . "

\n"; print "
\n"; print "

" . __( "List of cached files (red: expired, green: pdf is delivered from cache)", "article2pdf" ) . "

"; print "\n"; print "\n"; print "
"; // Display cache files $cache_counter_green = 0; $cache_counter_red = 0; $cache_counter = 0; if( !empty( $this -> a2p_AdminOptions[ 'PDFOptionCacheTime' ] ) ) { if( $d = opendir( A2P_CACHEPATH ) ) { while( false !== ($cf = readdir( $d ) ) ) { $fSuffix_Arr = explode( ".", $cf ); if( end( $fSuffix_Arr ) == 'pdf' && $fSuffix_Arr[ 0 ] == 'a2p' && $fSuffix_Arr[ 1 ] == 'cache' ) { if( filemtime( A2P_CACHEPATH . $cf ) < (time() - $this -> a2p_AdminOptions[ 'PDFOptionCacheTime' ]) ) { $cache_counter_red++; $col = 'red'; } else { $cache_counter_green++; $col = 'green'; } echo "$cf (" . date( "d.m.y H:i:s", filemtime( A2P_CACHEPATH . $cf ) ) . ")
\n"; } } $cache_counter = $cache_counter_green + $cache_counter_red; } if( !$cache_counter ) echo __( "Sorry, no files are cached at the moment.", "article2pdf" ); } else echo __( "Caching is disabled.", "article2pdf" ); print "
\n"; if( $cache_counter ) { echo ""; echo "$cache_counter_green " . __( "files are cached.", "article2pdf" ) . " "; echo "$cache_counter_red " . __( "files are cached and outdated.", "article2pdf" ) . "

"; echo "$cache_counter " . __( "files are cached total.", "article2pdf" ); echo "
"; } print "
\n"; print "\n"; print "
\n"; print "
\n"; print "
\n"; // Donate link and support informations print "
\n"; print "
\n"; print "

" . __( "Donate & support", "article2pdf" ) . "

\n"; print "
\n"; print __( "Please", "article2pdf" ) . " " . __( "DONATE", "article2pdf" ) . " " . __( "if you like this plugin.", "article2pdf" ) . "
"; print __( "Many thanks to Oliver for the great", "article2pdf" ) . " " . __( "FPDF library", "article2pdf" ) . ".
"; print "
" . __( "If you need support, want to report bugs or suggestions, drop me an ", "article2pdf" ) . " " . __( "email", "article2pdf" ) . " " . __( "or visit the", "article2pdf" ) . " " . __( "plugin homepage", "article2pdf" ) . ".
"; print "
" . __( "Final statements: Code is poetry. Motorcycles are cooler than cars.", "article2pdf" ); print "
"; print "
\n"; print "
\n"; // Close container print "
\n"; // Nice display if( version_compare( substr($wp_version, 0, 3), '2.6', '<' ) ) { ?> )(.*)()#siU', $p, $tables ); foreach( $tables[ 2 ] AS $tkey => $tcontent ) { $tcontent = str_replace( array( "\r", "\n" ), '', $tcontent ); $tcontent = preg_replace( '#()|()|()|()#siU', '', $tcontent ); $p_new = ''; preg_match_all( '#()(.*)()#siU', $tcontent, $rows ); foreach( $rows[ 2 ] AS $rkey => $row ) { preg_match_all( '#(|)(.*)(|)#siU', $row, $cells ); $p_new .= '|-====-|TR|' . count( $cells[ 2 ] ); foreach( $cells[ 2 ] AS $ckey => $ccontent ) { $cstart = $cells[ 1 ][ $ckey ]; $cend = $cells[ 3 ][ $ckey ]; if( strpos( strtolower( $cstart ), '(.*)#siU', $p, $matches ); $is_converted = false; $p_new = ''; foreach( $matches[ 1 ] AS $mkey => $href ) { $linkhtml = $matches[ 0 ][ $mkey ]; $linkcontent = $matches[ 2 ][ $mkey ]; if( strpos( $href, '#' ) !== 0 && !empty( $linkcontent ) ) { $p_first = substr( $p, 0, strpos( $p, $linkhtml ) ); $p_last = substr( $p, (strpos( $p, $linkhtml ) + strlen( $linkhtml )) ); $p_new .= $p_first; $p_new .= "|-====-|LINK|$href|$linkcontent|-====-|/LINK|"; $p_new .= $p_middle2; $p = preg_replace( '#^.*' . preg_quote( $linkhtml ) . '#sU', '', $p ); $is_converted = true; } } if( $is_converted ) { $p_new .= $p_last; return $p_new; } else return $p; } // Parse bold function _convert_bold( $p ) { return str_replace( array( "", "", "", "" ), array( "|-====-|B|", "|-====-|B|", "|-====-|/B|", "|-====-|/B|" ), $p ); } // Parse underline function _convert_underline( $p ) { return str_replace( array( "", "" ), array( "|-====-|U|", "|-====-|/U|" ), $p ); } // Parse italic function _convert_italic( $p ) { return str_replace( array( "", "", "", "" ), array( "|-====-|I|", "|-====-|I|", "|-====-|/I|", "|-====-|/I|" ), $p ); } // Parse blockquote function _convert_blockquote( $p ) { return str_replace( array( "
", "
" ), array( "|-====-|Q|", "|-====-|/Q|" ), $p ); } // Parse list items function _convert_listitem( $p ) { $p = str_replace( array( "
  • ", "
  • ", ), array( "|-====-|LI|", "|-====-|/LI|" ), $p ); return str_replace( array( "
      ", "
    ", "
      ", "
    ", ), array( "|-====-|UL|", "|-====-|/UL|", "|-====-|OL|", "|-====-|/OL|" ), $p ); } // Parse headings function _convert_heading( $p ) { preg_match_all( '//si', $p, $matches ); foreach( $matches[ 1 ] AS $h ) $p = str_replace( array( "", "" ), array( "|-====-|H$h|", "|-====-|/H$h|" ), $p ); return $p; } // Parse horizontal lines function _convert_lines( $p ) { return preg_replace( '##iU', '|-====-|__|', $p ); } // Set font style function _font_normal( &$pdf ) { $pdf -> SetFont( $this -> a2p_AdminOptions[ 'PDFOptionFont' ], '', $this -> a2p_AdminOptions[ 'PDFOptionFontSize' ] ); } function _font_underline( &$pdf ) { $pdf -> SetFont( $this -> a2p_AdminOptions[ 'PDFOptionFont' ], 'U', $this -> a2p_AdminOptions[ 'PDFOptionFontSize' ] ); } function _font_bold( &$pdf ) { $pdf -> SetFont( $this -> a2p_AdminOptions[ 'PDFOptionFont' ], 'B', $this -> a2p_AdminOptions[ 'PDFOptionFontSize' ] ); } function _font_italic( &$pdf ) { $pdf -> SetFont( $this -> a2p_AdminOptions[ 'PDFOptionFont' ], 'I', $this -> a2p_AdminOptions[ 'PDFOptionFontSize' ] ); } function _font_heading( &$pdf, $hlevel = 2 ) { $heading_font_size = $this -> a2p_AdminOptions[ 'PDFOptionFontSize' ] + (($this -> a2p_AdminOptions[ 'PDFOptionFontSize' ] / 2) / $hlevel); $pdf -> SetFont( $this -> a2p_AdminOptions[ 'PDFOptionFont' ], 'B', $heading_font_size ); } // Set margins function _margin_normal( &$pdf ) { $pdf -> SetLeftMargin( $this -> a2p_AdminOptions[ 'PDFTemplateMarginLeft' ] ); } function _margin_quote( &$pdf ) { $pdf -> SetLeftMargin( $this -> a2p_AdminOptions[ 'PDFTemplateMarginLeft' ] * 2 ); $pdf -> SetX( $this -> a2p_AdminOptions[ 'PDFTemplateMarginLeft' ] * 2 ); } // Cache: Get cachefile path function _cache_get_filename( &$post ) { $fname = 'a2p.cache.' . $post -> post_name . '.pdf'; return A2P_CACHEPATH . $fname; } // Cache: recreate pdf or deliver cached version function _cache_recreate( $cachefile ) { if( file_exists( $cachefile ) && !empty( $this -> a2p_AdminOptions[ 'PDFOptionCacheTime' ] ) ) { if( filemtime( $cachefile ) < (time() - $this -> a2p_AdminOptions[ 'PDFOptionCacheTime' ]) ) return true; else return false; } else return true; } } // Create class instance $a2p_Plugin = new article2pdf(); // PDF creation wrapper function wrapper_a2p_CreatePdf() { global $a2p_Plugin; if( strpos( $_SERVER[ 'REQUEST_URI' ], 'article2pdf=' ) ) $a2p_Plugin -> a2p_CreatePdf(); } // Admin wrapper function wrapper_a2p_AdminPage() { global $a2p_Plugin; add_options_page( 'article2pdf Options', 'article2pdf', 9, basename(__FILE__), array( &$a2p_Plugin, 'a2p_AdminPage' ) ); } // Add action: Install add_action( 'activate_article2pdf/article2pdf.php', array( &$a2p_Plugin, 'a2p_GetAdminOptions' ) ); // Add action: Admin page add_action( 'admin_menu', 'wrapper_a2p_AdminPage' ); // Add action: CreatePdf add_action( 'template_redirect', 'wrapper_a2p_CreatePdf' ); ?>