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', str_replace( 'plugins/article2pdf/../../', '', dirname(__FILE__) . "/../../uploads/" ) ); require_once( FPDF_INCLUDEPATH . 'fpdf.php' ); require_once( FPDI_INCLUDEPATH . 'fpdi.php' ); /** * Replacement for PHP 5 function sys_get_temp_dir */ if( !function_exists( 'sys_get_temp_dir' ) ) { function sys_get_temp_dir() { if( !empty( $_ENV[ 'TMP' ] ) ) return realpath($_ENV['TMP']); if( !empty( $_ENV[ 'TMPDIR' ] ) ) return realpath( $_ENV[ 'TMPDIR' ] ); if( !empty( $_ENV[ 'TEMP' ] ) ) return realpath( $_ENV[ 'TEMP' ] ); $tempfile = tempnam( uniqid( rand(), TRUE ), '' ); if( file_exists( $tempfile ) ) { unlink( $tempfile ); return realpath( dirname( $tempfile ) ); } } } /** * The main plugin class */ class article2pdf { var $a2p_AdminOptionsName; var $a2p_AdminOptions; var $_page_counter; // Construct function __construct() { $this -> a2p_AdminOptionsName = 'a2pPlugin_AdminOptions'; $this -> a2p_AdminOptions = $this -> a2p_GetAdminOptions(); $this -> _page_counter = 0; } // 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' => '', 'PDFTemplatePath' => FPDF_TEMPLATEPATH, '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, 'PDFOptionCachePath' => A2P_CACHEPATH, 'PDFPageCountPosX' => 10, 'PDFPageCountPosY' => 10, 'PDFPageCountString' => 'Page %%page%% of %%pagestotal%%', 'PDFPageCountFontSize' => '8', 'PDFOptionDenySearchengines' => 'false', 'PDFOptionRedirectMethod' => 'HTTP' ); // Load existing options $_a2pOptions = get_option( $this -> a2p_AdminOptionsName ); // Overwrite defaults $update = false; if( count( $_a2pOptions ) ) { foreach( $_a2pOptions AS $oKey => $oVal ) { if( $oKey == 'PDFTemplatePath' && empty( $oVal ) ) { $oVal = FPDF_TEMPLATEPATH; $update = true; } if( $oKey == 'PDFOptionCachePath' && empty( $oVal ) ) { $oVal = A2P_CACHEPATH; $update = true; } $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 ) { update_option( $this -> a2p_AdminOptionsName, $a2pOptions ); } // Return options return $a2pOptions; } // Create pdf function a2p_CreatePdf( $content_html ) { // Get post global $post; // Save content html to new var $content = $content_html; // Set base url $base_url = get_option( 'siteurl' ); // Search engine spider check (works only with redirect method HTTP!) if( $this -> a2p_AdminOptions[ 'PDFOptionDenySearchengines' ] == 'true' && $this -> a2p_AdminOptions[ 'PDFOptionRedirectMethod' ] != 'JS' && $this -> _is_bot() ) { // Drop all output buffers $this -> _ob_end_clean(); // Send a 410 gone to stop spidering and tell to remove already spidered content header( 'HTTP/1.1 410 Gone' ); header( 'Status: 410 Gone' ); die(); } // On debug never deliver from cache! if( strpos( $_SERVER[ 'REQUEST_URI' ], 'debug_pdf_file=1' ) !== false || $_POST[ 'debug_pdf_file' ] == '1' ) { $this -> a2p_AdminOptions[ 'PDFOptionCacheTime' ] = 0; $debug_pdf_file = 1; } else $debug_pdf_file = 0; 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( $this -> _decode_utf( strip_tags( $post -> post_title ) ) ); if( !empty( $this -> a2p_AdminOptions[ 'PDFTemplateFile' ] ) ) { $pdf -> setSourceFile( $this -> a2p_AdminOptions[ 'PDFTemplatePath' ] . $this -> a2p_AdminOptions[ 'PDFTemplateFile' ] ); $pdf -> tplIdx = $pdf -> importPage( 1 ); } $this -> _add_page( $pdf ); if( !empty( $this -> a2p_AdminOptions[ 'PDFTemplateFile' ] ) ) $pdf -> useTemplate( $pdf -> tplIdx ); $pdf -> SetLineWidth( 0.2 ); $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[ 'PDFTemplateMarginTop' ] ); $pdf -> SetFont( $this -> a2p_AdminOptions[ 'PDFOptionFont' ], '', $this -> a2p_AdminOptions[ 'PDFOptionFontSize' ] ); $pdf -> AliasNbPages( '%%pagestotal%%' ); // 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( $this -> _decode_utf( html_entity_decode( strip_tags( $post -> post_title ), ENT_QUOTES, 'UTF-8' ) ) ) / ($pdf -> w - $pdf -> lMargin - $pdf -> rMargin) ), $this -> _decode_utf( html_entity_decode( strip_tags( $post -> post_title ), ENT_QUOTES, 'UTF-8' ) ), 1, 1, 'C' ); $this -> _font_normal( $pdf ); $pdf -> Ln(); // Write body // Convert html to natural tags $convertRegEx = array( '//iU' => '', '/<\/div>/iU' => '', '/.*<\/script>/siU' => '', '//iU' => '', '/<\/span>/iU' => '', '//iU' => '
', '//iU' => '
    ', '//iU' => '
      ', '//iU' => '
    1. ', '//iU' => '
      ', '//iU' => '
      ',
      							'//iU' => '',
      							'//iU' => '',
      							'//iU' => '',
      							'//iU' => '',
      							'//iU' => '',
      							'//iU' => '',
      							'//iU' => '
      ', '//iU' => '' /*'/<.*>/iU' => '<>',*/ ); $content = preg_replace( array_keys( $convertRegEx ), $convertRegEx, $content ); // Prepare tables to be in a single paragraph (easier to parse) preg_match_all( '#.*(.*).*#siU', $content, $tables ); if( count( $tables[ 1 ] ) ) { foreach( $tables[ 1 ] AS $tkey => $tbl ) { $tbl = str_replace( array( "\n", "\r" ), '', $tbl ); $content = str_replace( $tables[ 1 ][ $tkey ], $tbl, $content ); } } // Explore by paragraph $paragraphs_array = explode( "\n", $content ); $isFirstParagraph = true; $link_href = ''; $ol_counter = 0; foreach( $paragraphs_array AS $pkey => $p ) { $page_before = $pdf -> PageNo(); $p = trim( $p ); if( !empty( $p ) ) { // Convert tables $p = $this -> _convert_tables( $p ); // Convert code $p = $this -> _convert_code( $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, 5 ) == 'CODE|' ) { $this -> _font_code( $pdf ); $part = substr( $part, 5 ); $pdf -> MultiCell( 0, $this -> a2p_AdminOptions[ 'PDFOptionLineHeight' ], $this -> _decode_utf( html_entity_decode( $part, ENT_QUOTES, 'UTF-8' ) ), 1, 'L' ); $part = ''; } if( substr( $part, 0, 3 ) == 'UL|' || substr( $part, 0, 3 ) == 'OL|' ) { if( substr( $part, 0, 3 ) == 'OL|' ) $ol_counter = 1; $this -> _margin_quote( $pdf ); $part = substr( $part, 3 ); $breaks_after = 1; } if( substr( $part, 0, 3 ) == 'LI|' ) { $part = substr( $part, 3 ); if( $ol_counter == 0 ) { $part = ' ' . $part; } else { $part = "$ol_counter. " . $part; $ol_counter++; } } 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 = $this -> _decode_utf( html_entity_decode( strip_tags( trim( substr( $part, 3 ) ) ), ENT_QUOTES, 'UTF-8' ) ); $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 = $this -> _decode_utf( html_entity_decode( strip_tags( trim( substr( $part, 3 ) ) ), ENT_QUOTES, 'UTF-8' ) ); $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 ) { $local_img_path = str_replace( $base_url, '', $img ); $img = ABSPATH . (substr( $local_img_path, 0, 1 ) === '/' ? substr( $local_img_path, 1 ) : $local_img_path); } // 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) ) $this -> _add_page( $pdf ); } // 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 ) == '/CODE|' ) { $this -> _font_normal( $pdf ); $part = substr( $part, 6 ); } 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|' ) { if( substr( $part, 0, 4 ) == '/OL|' ) $ol_counter = 0; $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 = $this -> _decode_utf( html_entity_decode( strip_tags( $part ), ENT_QUOTES, 'UTF-8' ) ); 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() ) { if( !empty( $this -> a2p_AdminOptions[ 'PDFTemplateFile' ] ) ) $pdf -> useTemplate( $pdf -> tplIdx ); $this -> _add_page_count( $pdf ); } } // Get pdfdata and store in cache, copy it to tmp dir $pdfdata = $pdf -> Output( '', 'S' ); if( !empty( $this -> a2p_AdminOptions[ 'PDFOptionCacheTime' ] ) && is_writable( $this -> a2p_AdminOptions[ 'PDFOptionCachePath' ] ) ) file_put_contents( $cachefile, $pdfdata ); } // Copy cache file to tmp file or write tmp file from pdf data $tmprand = substr( md5( rand( 10000000, 99999999 ) . $_SERVER[ 'REMOTE_ADDR' ] ), 0, 6 ); $tmpfile = sys_get_temp_dir() . '/a2p.tmp.' . $post -> post_name . '.' . $tmprand . '.pdf'; if( !empty( $this -> a2p_AdminOptions[ 'PDFOptionCacheTime' ] ) && is_writable( $this -> a2p_AdminOptions[ 'PDFOptionCachePath' ] ) ) copy( $cachefile, $tmpfile ); else file_put_contents( $tmpfile, $pdfdata ); // Redirect method HTTP if( $this -> a2p_AdminOptions[ 'PDFOptionRedirectMethod' ] == 'HTTP' ) { // Drop all output buffers $this -> _ob_end_clean(); // Redirect to download the tmp file if( $debug_pdf_file ) header( "Location: $base_url" . (substr( $base_url, -1 ) != '/' ? '/' : '') . "wp-content/plugins/article2pdf/article2pdf_getfile.php?p=" . urlencode( $post -> post_name ) . "&r=$tmprand&debug_pdf_file=1" ); else header( "Location: $base_url" . (substr( $base_url, -1 ) != '/' ? '/' : '') . "wp-content/plugins/article2pdf/article2pdf_getfile.php?p=" . urlencode( $post -> post_name ) . "&r=$tmprand" ); die(); } // Redirect method JavaScript else { if( $debug_pdf_file ) $content_html .= ""; else $content_html .= ""; return $content_html; } } } // Adminpage function a2p_AdminPage() { if( function_exists( 'load_plugin_textdomain' ) ) { load_plugin_textdomain( 'article2pdf', 'wp-content/plugins/article2pdf' ); } $open = 0; // Create a test pdf file if( $_POST[ 'a2p_admin_action' ] == 'create_test_pdf' ) { $this -> a2p_AdminOptions[ 'PDFOptionCacheTime' ] = 0; $this -> a2p_AdminOptions[ 'PDFOptionRedirectMethod' ] = 'HTTP'; global $post; $post = new stdClass; $post -> ID = rand( 10000, 10000000 ); $post -> post_title = 'TEST PDF'; $post -> post_date = 'now'; $post -> post_name = 'test-pdf-' . substr( md5( rand() ), 0, 5 ); $this -> a2p_CreatePdf( stripslashes( $_POST[ 'testhtml' ] ) ); $open = 5; } // Delete single file from cache if( $_GET[ 'a2p_admin_action' ] == 'deletecachefile' ) { $cachefile = str_replace( '..', '', urldecode( $_GET[ 'cachefile' ] ) ); if( file_exists( $this -> a2p_AdminOptions[ 'PDFOptionCachePath' ] . $cachefile ) ) unlink( $this -> a2p_AdminOptions[ 'PDFOptionCachePath' ] . $cachefile ); $open = 4; } // Get file from cache if( $_GET[ 'a2p_admin_action' ] == 'getcachefile' ) { $cachefile = str_replace( '..', '', urldecode( $_GET[ 'cachefile' ] ) ); if( file_exists( $this -> a2p_AdminOptions[ 'PDFOptionCachePath' ] . $cachefile ) ) { // Drop all output buffers $this -> _ob_end_clean(); header( "Content-Type: application/pdf" ); header( "Content-Disposition: attachment; filename=\"" . $cachefile . "\"" ); echo file_get_contents( $this -> a2p_AdminOptions[ 'PDFOptionCachePath' ] . $cachefile ); die(); } $open = 4; } // Delete expired cache files if( $_GET[ 'a2p_admin_action' ] == 'cache_delete_expired' ) { if( is_writeable( $this -> a2p_AdminOptions[ 'PDFOptionCachePath' ] ) ) { if( $d = opendir( $this -> a2p_AdminOptions[ 'PDFOptionCachePath' ] ) ) { while( false !== ($cf = readdir( $d ) ) ) { $fSuffix_Arr = explode( ".", $cf ); if( end( $fSuffix_Arr ) == 'pdf' && $fSuffix_Arr[ 0 ] == 'a2p' && $fSuffix_Arr[ 1 ] == 'cache' ) { if( filemtime( $this -> a2p_AdminOptions[ 'PDFOptionCachePath' ] . $cf ) < (time() - $this -> a2p_AdminOptions[ 'PDFOptionCacheTime' ]) ) unlink( $this -> a2p_AdminOptions[ 'PDFOptionCachePath' ] . $cf ); } } } print "

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

      "; $open = 4; } else print __( "Sorry, the cache directory is not writeable. Please chmod the directory to a permission that allows the webserver to write into that directory.", "article2pdf" ); } // Delete cache if( $_POST[ 'a2p_admin_action' ] == 'cache_delete' ) { if( is_writeable( $this -> a2p_AdminOptions[ 'PDFOptionCachePath' ] ) ) { if( $d = opendir( $this -> a2p_AdminOptions[ 'PDFOptionCachePath' ] ) ) { while( false !== ($cf = readdir( $d ) ) ) { $fSuffix_Arr = explode( ".", $cf ); if( end( $fSuffix_Arr ) == 'pdf' && $fSuffix_Arr[ 0 ] == 'a2p' && $fSuffix_Arr[ 1 ] == 'cache' ) { unlink( $this -> a2p_AdminOptions[ 'PDFOptionCachePath' ] . $cf ); } } } print "

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

      "; $open = 4; } else print "

      " . __( "Sorry, the cache directory is not writeable. Please chmod the directory to a permission that allows the webserver to write into that directory.", "article2pdf" ) . "

      "; } // Delete template file if( $_POST[ 'a2p_admin_action' ] == 'delete' ) { if( !empty( $_POST[ 'PDFTemplateFile' ] ) ) { if( $_POST[ 'PDFTemplateFile' ] != $this -> a2p_AdminOptions[ 'PDFTemplateFile' ] ) { if( unlink( $this -> a2p_AdminOptions[ 'PDFTemplatePath' ] . $_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 template file if( $_POST[ 'a2p_admin_action' ] == 'upload' ) { if( is_uploaded_file( $_FILES[ 'templatefile' ][ 'tmp_name' ] ) ) { if( is_writeable( $this -> a2p_AdminOptions[ 'PDFTemplatePath' ] ) ) { $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' ], $this -> a2p_AdminOptions[ 'PDFTemplatePath' ] . $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; } } // Set template file 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 ]); if( $oKey == 'PDFOptionCachePath' ) { if( !empty( $_POST[ $oKey ] ) ) $a2pOptionsNew[ $oKey ] = (substr( $_POST[ $oKey ], -1 ) != '/' ? $_POST[ $oKey ] . '/' : $_POST[ $oKey ]); else $a2pOptionsNew[ $oKey ] = A2P_CACHEPATH; } if( $oKey == 'PDFTemplatePath' ) { if( !empty( $_POST[ $oKey ] ) ) $a2pOptionsNew[ $oKey ] = (substr( $_POST[ $oKey ], -1 ) != '/' ? $_POST[ $oKey ] . '/' : $_POST[ $oKey ]); else $a2pOptionsNew[ $oKey ] = FPDF_TEMPLATEPATH; } } update_option( $this -> a2p_AdminOptionsName, $a2pOptionsNew ); $this -> a2p_AdminOptions = $a2pOptionsNew; if( $_POST[ 'createdir' ] == 'yes' ) { if( !file_exists( $_POST[ 'PDFTemplatePath' ] ) ) mkdir( $_POST[ 'PDFTemplatePath' ] ); } 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"; if( !is_writeable( $this -> a2p_AdminOptions[ 'PDFTemplatePath' ] ) ) { print "\n"; } print "\n"; print "\n"; if( strpos( $this -> a2p_AdminOptions[ 'PDFTemplatePath' ], 'article2pdf/contributed/pdftemplates' ) !== false ) { print ""; } print "
      "; print __( "Enter the absolute path to the directory where the pdf template files were stored. Important: The directory MUST be writeable by the webserver. The last character MUST be a slash.
      Hint: After changing this you have to upload a new pdf template file to that directory.", "article2pdf" ); print "
      a2p_AdminOptions[ 'PDFTemplatePath' ] . "\"/>
      "; print __( "Sorry, the cache directory is not writeable. Please chmod the directory to a permission that allows the webserver to write into that directory.", "article2pdf" ); print "
      "; print __( "Try to create this directory on change? (e.g. if your enter something like '[...]/wp-content/uploads/pdftemplates' what is always a good choice!)", "article2pdf" ); print ""; print " " . __( "Yes, do that!", "article2pdf" ) . "\n"; print "
      "; print str_replace( '%%templatepath%%', $this -> a2p_AdminOptions[ 'PDFTemplateFile' ], __( "To use a pdf file as template for your genereated pdf files, just place the template file in %%templatepath%% and choose the file from the select box.", "article2pdf" ) ) . "\n"; print ""; $sTpl = "\n"; print $sTpl; print "
      "; print str_replace( '%%suggestion%%', A2P_CACHEPATH . 'pdftemplates/', __( "Warning! The template path you have selected is not safe because the templates are stored under the plugin directory. If you update a plugin with the WordPress built in automatic plugin update feature ALL FILES in the article2pdf plugin directory were deleted - including your pdf template files. So if you don't want to upload the pdf template file again after every update, here a suggestion of a good template path: %%suggestion%% (be sure to activate 'Try to create this directory on change').", "article2pdf" ) ) . "\n"; 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.", "article2pdf" ); print ""; $fonts_arr = array( 'Arial', 'Courier', 'Helvetica', 'Symbol', 'Times', 'ZapfDingBats' ); print "\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"; // PDFOptionPageCountX/Y/string print "

      " . __( "Display page count", "article2pdf" ) . "

      \n"; print "\n"; print ""; print "\n"; print "\n"; print "\n"; print "\n"; print "
      " . __( "If you don't want to use this feature just enter nothing and save.", "article2pdf" ) . "
      "; print __( "Enter the X position where the page count will be inserted (in mm, from left)", "article2pdf" ); print ""; print " a2p_AdminOptions[ 'PDFPageCountPosX' ] . "\"/> \n"; print "
      "; print __( "Enter the Y position where the page count will be inserted (in mm, from top)", "article2pdf" ); print ""; print " a2p_AdminOptions[ 'PDFPageCountPosY' ] . "\"/> \n"; print "
      "; print __( "Enter the string to be printed (%%page%% is replaced by the actual page number and %%pagestotal%% by the total count of pages, e.g.: Page %%page%% of %%pagestotal%%)", "article2pdf" ); print ""; print " a2p_AdminOptions[ 'PDFPageCountString' ] . "\"/> \n"; print "
      "; print __( "Enter the font size of the string", "article2pdf" ); print ""; print " a2p_AdminOptions[ 'PDFPageCountFontSize' ] . "\"/> \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"; if( is_writeable( $this -> a2p_AdminOptions[ 'PDFOptionCachePath' ] ) ) { print "\n"; } else { print "\n"; print "\n"; } print "
      "; print __( "Enter the absolute path to the directory where the cache files were stored. Only modify if you got problems with the default value (try '/tmp/' if nothing works). Important: The directory MUST be writeable by the webserver. The last character MUST be a slash.", "article2pdf" ); print " a2p_AdminOptions[ 'PDFOptionCachePath' ] . "\"/>
      "; 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 "
      "; print __( "Sorry, the cache directory is not writeable. Please chmod the directory to a permission that allows the webserver to write into that directory.", "article2pdf" ); print "
      \n"; // PDFOptionDenySearchengines: select true or false print "

      " . __( "Deny generated pdf files to search enging spiders", "article2pdf" ) . "

      "; print "\n"; print "\n"; print "
      "; print __( "If you don't want search engine spiders to crawl your pdf documents activate the following option. The plugin will send a '410 GONE' response to the crawlers.", "article2pdf" ); print ""; print "\n"; print "
      \n"; // PDFOptionRedirectMethod: select HTTP or JS print "

      " . __( "PDF download redirect method", "article2pdf" ) . "

      "; print "\n"; print "\n"; print "\n"; print "
      "; print __( "Please select how the user get redirected to the plugin file that sends the PDF as download to the browser. 99% can select HTTP here, but if you got problems select JavaScript.", "article2pdf" ); print ""; print "\n"; print "
      "; print __( "This path is used to temporarily store the pdf file before sending it to the user:", "article2pdf" ); print ""; print sys_get_temp_dir(); print "
      \n"; // Submit options 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 str_replace( '/wp-content/plugins/article2pdf/contributed/pdftemplates', $this -> a2p_AdminOptions[ 'PDFTemplatePath' ], "

      " . __( "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 if( !empty( $_GET[ 'cache_sort_by' ] ) ) $open = 4; 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 "
      "; print __( "Sort by:", "article2pdf" ) . " [" . __( "state", "article2pdf" ) . "] [" . __( "name", "article2pdf" ) . "]

      "; // Display cache files $cache_counter_green = 0; $cache_counter_red = 0; $cache_counter = 0; if( !empty( $this -> a2p_AdminOptions[ 'PDFOptionCacheTime' ] ) ) { if( is_writeable( $this -> a2p_AdminOptions[ 'PDFOptionCachePath' ] ) ) { if( $d = opendir( $this -> a2p_AdminOptions[ 'PDFOptionCachePath' ] ) ) { $cache_content = array(); while( false !== ($cf = readdir( $d ) ) ) { $fSuffix_Arr = explode( ".", $cf ); if( end( $fSuffix_Arr ) == 'pdf' && $fSuffix_Arr[ 0 ] == 'a2p' && $fSuffix_Arr[ 1 ] == 'cache' ) { if( filemtime( $this -> a2p_AdminOptions[ 'PDFOptionCachePath' ] . $cf ) < (time() - $this -> a2p_AdminOptions[ 'PDFOptionCacheTime' ]) ) { $cache_counter_red++; $col = 'red'; } else { $cache_counter_green++; $col = 'green'; } $cache_content[ $cf ] = $col; } } $cache_counter = $cache_counter_green + $cache_counter_red; if( $_GET[ 'cache_sort_by' ] == 'name' || empty( $_GET[ 'cache_sort_by' ] ) ) ksort( $cache_content ); else arsort( $cache_content ); foreach( $cache_content AS $cf => $col ) { echo "$cf (" . date( "d.m.y H:i:s", filemtime( $this -> a2p_AdminOptions[ 'PDFOptionCachePath' ] . $cf ) ) . ") [" . __( "delete", "article2pdf" ) . "]
      \n"; } } if( !$cache_counter ) echo __( "Sorry, no files are cached at the moment.", "article2pdf" ); } else print __( "Sorry, the cache directory is not writeable. Please chmod the directory to a permission that allows the webserver to write into that directory.", "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"; // Test PDF creation print "
      \n"; print "
      \n"; print "
      \n"; print "\n"; print "

      " . __( "PDF creation testsuite", "article2pdf" ) . "

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

      " . __( "Copy and paste the post html from your blog into the field and submit the form.", "article2pdf" ) . "

      "; print "

      "; print "

      " . __( "Don't send PDF for download. Just display the pdf source and possible failures for debugging.", "article2pdf" ) . "

      "; print "
      \n"; print "\n"; print "
      "; 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 "
      " . __( "Translations: ", "article2pdf" ) . " Alejandro Urrutia Daglio (Español), Marc Schieferdecker (Deutsch)
      "; print "
      " . __( "And this persons I thank for a donation:", "article2pdf" ) . " Marcus Hochstadt, Frank Becker
      "; 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 ), '", "
      " ), array( "|-====-|CODE|", "|-====-|CODE|", "|-====-|/CODE|", "|-====-|/CODE|" ), $p ); } // Parse links function _convert_links( $p ) { preg_match_all( '#(.*)#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( "
    2. ", "
    3. ", "
        ", "
      ", "
        ", "
      " ), array( "|-====-|LI|", "|-====-|/LI|", "|-====-|UL|", "|-====-|/UL|", "|-====-|OL|", "|-====-|/OL|" ), $p ); return $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_code( &$pdf ) { $pdf -> SetFont( 'Courier', '', $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 ); } // Add page to pdf function _add_page( &$pdf ) { $pdf -> AddPage(); $this -> _add_page_count( $pdf ); // Set to start of $pdf -> SetXY( $this -> a2p_AdminOptions[ 'PDFTemplateMarginLeft' ], $this -> a2p_AdminOptions[ 'PDFTemplateMarginRight' ] ); } // Write page count function _add_page_count( &$pdf ) { if( !empty( $this -> a2p_AdminOptions[ 'PDFPageCountString' ] ) && !empty( $this -> a2p_AdminOptions[ 'PDFPageCountPosX' ] ) && !empty( $this -> a2p_AdminOptions[ 'PDFPageCountPosY' ] ) && !empty( $this -> a2p_AdminOptions[ 'PDFPageCountFontSize' ] ) ) { $this -> _page_counter++; $page_str = str_replace( '%%page%%', $this -> _page_counter, $this -> a2p_AdminOptions[ 'PDFPageCountString' ] ); $x = $pdf -> GetX(); $y = $pdf -> GetY(); $lMargin = $pdf -> lMargin; $tMargin = $pdf -> tMargin; $pdf -> SetLeftMargin( 0 ); $pdf -> SetTopMargin( 0 ); $pdf -> SetAutoPageBreak( false, 0 ); $pdf -> SetXY( $this -> a2p_AdminOptions[ 'PDFPageCountPosX' ], $this -> a2p_AdminOptions[ 'PDFPageCountPosY' ] ); $pdf -> SetFont( $this -> a2p_AdminOptions[ 'PDFOptionFont' ], '', $this -> a2p_AdminOptions[ 'PDFPageCountFontSize' ] ); $pdf -> Write( 0, $page_str ); $pdf -> SetLeftMargin( $lMargin ); $pdf -> SetTopMargin( $tMargin ); $pdf -> SetAutoPageBreak( true, $this -> a2p_AdminOptions[ 'PDFTemplateMarginBottom' ] ); $pdf -> SetFont( $this -> a2p_AdminOptions[ 'PDFOptionFont' ], '', $this -> a2p_AdminOptions[ 'PDFOptionFontSize' ] ); $pdf -> SetXY( $x, $y ); } } /* * Cache functions */ // Cache: Get cachefile path function _cache_get_filename( &$post ) { $fname = 'a2p.cache.' . $post -> post_name . '.pdf'; return $this -> a2p_AdminOptions[ 'PDFOptionCachePath' ] . $fname; } // Cache: recreate pdf or deliver cached version function _cache_recreate( $cachefile ) { if( file_exists( $cachefile ) && !empty( $this -> a2p_AdminOptions[ 'PDFOptionCacheTime' ] ) && is_writeable( $this -> a2p_AdminOptions[ 'PDFOptionCachePath' ] ) ) { if( filemtime( $cachefile ) < (time() - $this -> a2p_AdminOptions[ 'PDFOptionCacheTime' ]) ) return true; else return false; } else return true; } // Cache: remove by post ID function _cache_remove_by_postid( $post_ID ) { $pdfpost = get_post( $post_ID ); $fname = $this -> a2p_AdminOptions[ 'PDFOptionCachePath' ] . 'a2p.cache.' . $pdfpost -> post_name . '.pdf'; if( file_exists( $fname ) ) unlink( $fname ); } /* * OB functions */ // Kill ALL Buffers! function _ob_end_clean() { $ob_level = ob_get_level(); while( $ob_level > 0 ) { ob_end_clean(); $ob_level--; } } } // Create class instance $a2p_Plugin = new article2pdf(); /** * Admin hooks */ // 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: Admin page add_action( 'admin_menu', 'wrapper_a2p_AdminPage' ); /** * Init hooks */ // Store page content in buffer if plugin is active, because of header redirection if( $a2p_Plugin -> a2p_AdminOptions[ 'PDFOptionRedirectMethod' ] == 'HTTP' || strpos( $_SERVER[ 'REQUEST_URI' ], 'a2p_admin_action=getcachefile' ) || $_POST[ 'a2p_admin_action' ] == 'create_test_pdf' ) { function a2p_init() { ob_start(); } // With this I drop rendered content (ob_end_clean is called by a2p_CreatePdf) if( strpos( $_SERVER[ 'REQUEST_URI' ], 'article2pdf=' ) || strpos( $_SERVER[ 'REQUEST_URI' ], 'a2p_admin_action=getcachefile' ) || $_POST[ 'a2p_admin_action' ] == 'create_test_pdf' ) add_action( 'plugins_loaded', 'a2p_init' ); } /** * PDF creation hooks */ // PDF creation wrapper function wrapper_a2p_CreatePdf( $content ) { global $a2p_Plugin; return $a2p_Plugin -> a2p_CreatePdf( $content ); } // Generate PDF from content after all shortcodes and filters are done if( strpos( $_SERVER[ 'REQUEST_URI' ], 'article2pdf=' ) ) add_filter( 'the_content', 'wrapper_a2p_CreatePdf', 9999 ); /** * Force recaching hooks */ // Post hooks add_action( 'edit_post', array( &$a2p_Plugin, '_cache_remove_by_postid' ) ); add_action( 'delete_post', array( &$a2p_Plugin, '_cache_remove_by_postid' ) ); /** * Misc hooks */ // Add action: Install - create default options add_action( 'activate_article2pdf/article2pdf.php', array( &$a2p_Plugin, 'a2p_GetAdminOptions' ) ); ?>
      ", "", "