File: /home/undanet/www/wp-content/themes/panoramic-child/mpdf/mpdf.php
<?php
add_action( 'template_redirect', 'mpdf_export', 98 );
function mpdf_export() {
if (isset($_GET['download'])
&& $_GET['download'] == 'pdf'
&& isset($_GET['option'])
) {
$pdfName = isset($_GET['pdfname']) ? $_GET['pdfname'] : __('doc','panoramic_child');
$isem = isset($_GET['isem']) ? true : false;
output_mpdf($_GET['option'], $pdfName, $isem);
exit;
}
}
function output_mpdf($option, $pdfName, $isem ) {
if ( is_readable( dirname(__FILE__) . '/vendor/autoload.php' ) ) {
require dirname(__FILE__) . '/vendor/autoload.php';
}
$pdfName = $pdfName . '.pdf';
$wp_content = get_option($option);
$wp_content = apply_filters( 'the_content', $wp_content );
$mpdf = new \Mpdf\Mpdf(array(
'format' => 'A4',
'orientation' => 'P',
'margin_left' => 15,
'margin_right' => 15,
'margin_top' => 35,
'margin_bottom' => 40,
'margin_header' => 9,
'margin_footer' => 7,
));
//$mpdf->showImageErrors = true;
$mpdf->curlAllowUnsafeSslRequests = true;
$mpdf->charset_in = 'utf-8';
$mpdf->title2annots = false;
$mpdf->onlyCoreFonts = true;
ob_start();
include( get_theme_file_path() . '/mpdf/templates/footer.php');
$pdf_footer = ob_get_clean();
ob_start();
include( get_theme_file_path() . '/mpdf/templates/header.php');
$pdf_header = ob_get_clean();
$mpdf->SetHTMLHeader( $pdf_header );
$mpdf->SetHTMLFooter( $pdf_footer );
$stylesheet = file_get_contents(get_theme_file_path() . '/mpdf/mpdf.css');
$mpdf->WriteHTML($stylesheet,\Mpdf\HTMLParserMode::HEADER_CSS);
$mpdf->WriteHTML($wp_content,\Mpdf\HTMLParserMode::HTML_BODY);
if ($isem) {
$mpdf->Output( WP_CONTENT_DIR . '/uploads/portalempleo/attachment/' . $pdfName, \Mpdf\Output\Destination::FILE );
sem_with_pdf($option, $pdfName);
}
$mpdf->Output( $pdfName, \Mpdf\Output\Destination::INLINE );
}
function sem_with_pdf($option, $pdfName) {
$attachment = WP_CONTENT_DIR . '/uploads/portalempleo/attachment/' . $pdfName ;
$mailopts = get_option($option . '_mail');
$mailto = $mailopts['mailto'];
$subject = $mailopts['subject'];
$message = $mailopts['message'];
$headers = array();
add_filter( 'wp_mail_content_type', function( $content_type ) {return 'text/html';});
$headers[] = 'From: ' . get_bloginfo( 'name' ) . ' <' . get_option('admin_email') . '>'."\r\n";
wp_mail( $mailto, $subject, $message, $headers, $attachment);
remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
}
?>