@ -50,6 +50,7 @@ class PDF {
//Converting the string into an array
//Converting the string into an array
$html_file_array = array($html_file_array);
$html_file_array = array($html_file_array);
}
}
$course_data = array();
$course_data = array();
if (!empty($course_code)) {
if (!empty($course_code)) {
$course_data = api_get_course_info($course_code);
$course_data = api_get_course_info($course_code);
@ -65,50 +66,51 @@ class PDF {
//Formatting the pdf
//Formatting the pdf
self::format_pdf($course_data);
self::format_pdf($course_data);
foreach ($html_file_array as $html_ file) {
foreach ($html_file_array as $file) {
$html_title = '';
$html_title = '';
//if the array provided contained subarrays with 'title' entry,
//if the array provided contained subarrays with 'title' entry,
// then print the title in the PDF
// then print the title in the PDF
if (is_array($html_ file) & & isset($html_ file['title'])) {
if (is_array($file) & & isset($file['title'])) {
$html_title = $html_ file['title'];
$html_title = $file['title'];
$html_ file = $html_ file['path'];
$file = $file['path'];
} else {
} else {
//we suppose we've only been sent a file path
//we suppose we've only been sent a file path
$html_title = basename($html_ file);
$html_title = basename($file);
}
}
if (empty($html_ file) & & !empty($html_title)) {
if (empty($file) & & !empty($html_title)) {
//this is a chapter, print title & skip the rest
//this is a chapter, print title & skip the rest
if ($print_title) {
if ($print_title) {
$this->pdf->WriteHTML('< html > < body > < h1 > '.$html_title.'< / h1 > < / body > < / html > ',2);
$this->pdf->WriteHTML('< html > < body > < h3 > '.$html_title.'< / h3 > < / body > < / html > ',2);
}
}
continue;
continue;
}
}
if (!file_exists($html_ file)) {
if (!file_exists($file)) {
//the file doesn't exist, skip
//the file doesn't exist, skip
continue;
continue;
}
}
//it's not a chapter but the file exists, print its title
//it's not a chapter but the file exists, print its title
if ($print_title) {
if ($print_title) {
$this->pdf->WriteHTML('< html > < body > < h2 > '.$html_title.'< / h2 > < / body > < / html > ',2);
$this->pdf->WriteHTML('< html > < body > < h3 > '.$html_title.'< / h3 > < / body > < / html > ',2);
}
}
$file_info = pathinfo($html_file);
$file_info = pathinfo($file);
$extension = $file_info['extension'];
if (in_array($extension, array('html', 'htm'))) {
$dirname = str_replace("\\", '/', $file_info['dirname']);
$dirname = str_replace("\\", '/', $file_info['dirname']);
$filename = $file_info['basename'];
$filename = $file_info['basename'];
$filename = str_replace('_',' ',$filename);
$filename = str_replace('_',' ',$filename);
$extension = $file_info['extension'];
if (!($extension == 'html' || $extension == 'htm')) {
continue;
}
if ($extension == 'html') {
if ($extension == 'html') {
$filename =basename($filename,'.html');
$filename =basename($filename,'.html');
} elseif($extension == 'htm'){
} elseif($extension == 'htm'){
$filename =basename($filename,'.htm');
$filename =basename($filename,'.htm');
}
}
$document_html = @file_get_contents($html_ file);
$document_html = @file_get_contents($file);
$document_html = preg_replace($clean_search, '', $document_html);
$document_html = preg_replace($clean_search, '', $document_html);
//absolute path for frames.css //TODO: necessary?
//absolute path for frames.css //TODO: necessary?
@ -139,15 +141,6 @@ class PDF {
}
}
}
}
}
}
//replace relative path by absolute path for resources
//$document_html= str_replace('src="/chamilo/main/default_course_document/', 'temp_template_path', $document_html);// before save src templates not apply
//$document_html= str_replace('src="/', 'temp_template_path', $document_html);// before save src templates not apply
//$document_html= str_replace('src="/chamilo/main/default_course_document/', 'temp_template_path', $document_html);// before save src templates not apply
//$src_http_www= 'src="'.api_get_path(WEB_COURSE_PATH).$course_data['path'].'/document/';
//$document_html= str_replace('src="',$src_http_www, $document_html);
//$document_html= str_replace('temp_template_path', 'src="/main/default_course_document/', $document_html);// restore src templates
api_set_encoding_html($document_html, 'UTF-8'); // The library mPDF expects UTF-8 encoded input data.
api_set_encoding_html($document_html, 'UTF-8'); // The library mPDF expects UTF-8 encoded input data.
$title = api_get_title_html($document_html, 'UTF-8', 'UTF-8'); // TODO: Maybe it is better idea the title to be passed through
$title = api_get_title_html($document_html, 'UTF-8', 'UTF-8'); // TODO: Maybe it is better idea the title to be passed through
// $_GET[] too, as it is done with file name.
// $_GET[] too, as it is done with file name.
@ -156,8 +149,15 @@ class PDF {
$title = $filename; // Here file name is expected to contain ASCII symbols only.
$title = $filename; // Here file name is expected to contain ASCII symbols only.
}
}
if (!empty($document_html)) {
$this->pdf->WriteHTML($document_html,2);
$this->pdf->WriteHTML($document_html,2);
}
}
} elseif (in_array($extension, array('jpg','jpeg','png','gif'))) {
//Images
$image = Display::img($file);
$this->pdf->WriteHTML('< html > < body > '.$image.'< / body > < / html > ',2);
}
}
if (empty($pdf_name)) {
if (empty($pdf_name)) {
$output_file = 'pdf_'.date('Y-m-d-his').'.pdf';
$output_file = 'pdf_'.date('Y-m-d-his').'.pdf';