Minor - format code

skala
Julio Montoya 11 years ago
parent 7e6ce67a4a
commit f9d3d9ad61
  1. 37
      main/inc/lib/pdf.lib.php

@ -99,26 +99,32 @@ class PDF {
* @param bool Whether to print the header, footer and watermark (true) or just the content (false) * @param bool Whether to print the header, footer and watermark (true) or just the content (false)
* @return void * @return void
*/ */
public function html_to_pdf($html_file_array, $pdf_name = '', $course_code = null, $print_title = false, $complete_style = true) { public function html_to_pdf($html_file_array, $pdf_name = '', $course_code = null, $print_title = false, $complete_style = true)
if ($complete_style === false) { error_log(__FUNCTION__.' with no style'); } {
if ($complete_style === false) {
error_log(__FUNCTION__.' with no style');
}
if (empty($html_file_array)) { if (empty($html_file_array)) {
return false; return false;
} }
if (is_array($html_file_array)) { if (is_array($html_file_array)) {
if (count($html_file_array) == 0) if (count($html_file_array) == 0) {
return false; return false;
}
} else { } else {
if (!file_exists($html_file_array)) { if (!file_exists($html_file_array)) {
return false; return false;
} }
//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);
} else { } else {
$course_data = api_get_course_info(); $course_data = api_get_course_info();
} }
@ -148,15 +154,15 @@ class PDF {
//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($file) && isset($file['title'])) { if (is_array($file) && isset($file['title'])) {
$html_title = $file['title']; $html_title = $file['title'];
$file = $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($file); $html_title = basename($file);
} }
if (empty($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><h3>'.$html_title.'</h3></body></html>'.$page_break, 2); $this->pdf->WriteHTML('<html><body><h3>'.$html_title.'</h3></body></html>'.$page_break, 2);
} }
@ -165,7 +171,7 @@ class PDF {
if (!file_exists($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
@ -178,12 +184,12 @@ class PDF {
if (in_array($extension, array('html', 'htm'))) { if (in_array($extension, array('html', 'htm'))) {
$filename = $file_info['basename']; $filename = $file_info['basename'];
$filename = str_replace('_',' ',$filename); $filename = str_replace('_', ' ', $filename);
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($file); $document_html = @file_get_contents($file);
@ -193,9 +199,8 @@ class PDF {
$absolute_css_path = api_get_path(WEB_CODE_PATH).'css/'.api_get_setting('stylesheets').'/frames.css'; $absolute_css_path = api_get_path(WEB_CODE_PATH).'css/'.api_get_setting('stylesheets').'/frames.css';
$document_html = str_replace('href="./css/frames.css"', $absolute_css_path, $document_html); $document_html = str_replace('href="./css/frames.css"', $absolute_css_path, $document_html);
if (!empty($course_data['path'])) { if (!empty($course_data['path'])) {
$document_html= str_replace('../','',$document_html); $document_html= str_replace('../', '', $document_html);
$document_path = api_get_path(SYS_COURSE_PATH).$course_data['path'].'/document/'; $document_path = api_get_path(SYS_COURSE_PATH).$course_data['path'].'/document/';
$doc = new DOMDocument(); $doc = new DOMDocument();

Loading…
Cancel
Save