Source for file openoffice_text_document.class.php
Documentation is available at openoffice_text_document.class.php
* Defines the OpenOfficeDocument class, which is meant as a conversion
* tool from Office text documents (.doc, .sxw, .odt, .docx) to
* @package dokeos.learnpath.openofficedocument
* @author Eric Marguin <eric.marguin@dokeos.com>
* @license GNU/GPL - See Doke
* Defines the "OpenOfficeTextDocument" child of class "learnpath"
* @package dokeos.learnpath.openofficedocument
require_once('openoffice_document.class.php');
* Class constructor. Calls the parent class and initialises the local attribute split_steps
* @param boolean Whether to split steps (true) or make one large page (false)
* @param string Course code
* @param integer Resource ID
* @param integer Creator user id
* Gets html pages and compose them into a learning path
* @param array The files that will compose the generated learning path. Unused so far.
* @return boolean False if file does not exit. Nothing otherwise.
// we get a content where ||page_break|| indicates where the page is broken
if(!file_exists($this->base_work_dir. '/'. $this->created_dir. '/'. $this->file_name. '.html')){return false;}
$content = file_get_contents($this->base_work_dir. '/'. $this->created_dir. '/'. $this->file_name. '.html');
unlink($this->base_work_dir. '/'. $this->file_path);
unlink($this->base_work_dir. '/'. $this->created_dir. '/'. $this->file_name. '.html');
// the file is utf8 encoded and it seems to make problems with special quotes.
// then we htmlentities that, we replace these quotes and html_entity_decode that in good charset
// set the path to pictures to absolute (so that it can be modified in fckeditor)
list ($header, $body) = explode('<BODY',$content);
// remove font-family styles
$header = preg_replace("|font\-family[^;]*;|i", "",$header);
if(empty($my_style)){$my_style = 'dokeos_classic';}
$style_to_import = "<style type=\"text/css\">\r\n";
$style_to_import .= "</style>\r\n";
$header = preg_replace("|</head>|i", "\r\n$style_to_import\r\n\\0",$header);
// line break before and after picture
case 'per_page' : $this -> dealPerPage($header,$body); break;
* Manages chapter splitting
* @param string Chapter header
preg_match_all("|<h1[^>]*>([^(h1)+]*)</h1>|is",$content,$matches_temp);
//empty the fake chapters
for ($i= 0 ; $i< count($matches_temp[0]) ; $i++ ) {
if(trim($matches_temp[1][$i])!== '')
$matches[0][$new_index] = $matches_temp[0][$i];
$matches[1][$new_index] = $matches_temp[1][$i];
$intro_content = substr($content, 0, strpos($content, $matches[0][0]));
$items_to_create[get_lang('Introduction')] = $intro_content;
for ($i= 0 ; $i< count($matches[0]) ; $i++ ) {
if(empty($matches[1][$i]))
$content = strstr($content,$matches[0][$i]);
if($i+ 1!== count($matches[0]))
$chapter_content = substr($content, 0, strpos($content, $matches[0][$i+ 1]));
$chapter_content = $content;
$items_to_create[$matches[1][$i]] = $chapter_content;
foreach($items_to_create as $item_title=> $item_content)
$html_file = $this->created_dir. '-'. $i. '.html';
$handle = fopen($this->base_work_dir. $this->created_dir. '/'. $html_file,'w+');
fwrite($handle, $page_content);
$document_id = add_document($_course,$this->created_dir. '/'. $html_file,'file',filesize($this->base_work_dir. $this->created_dir. '/'. $html_file),$html_file);
//put the document in item_property update
$slide_name = str_replace(array("\r\n", "\r", "\n"), "", $slide_name);
$previous = learnpath::add_item(0, $previous, 'document', $document_id, $slide_name, '');
* @param string Page header
* @param string Page body
// split document to pages
$pages = explode('||page_break||',$body);
foreach($pages as $key=> $page_content)
{ // for every pages, we create a new file
$page_content = $this->format_page_content($header, $page_content, $this->base_work_dir. $this->created_dir);
$html_file = $this->created_dir. '-'. $key. '.html';
$handle = fopen($this->base_work_dir. $this->created_dir. '/'. $html_file,'w+');
fwrite($handle, $page_content);
$document_id = add_document($_course,$this->created_dir. $html_file,'file',filesize($this->base_work_dir. $this->created_dir. $html_file),$html_file);
//put the document in item_property update
$previous = learnpath::add_item(0, $previous, 'document', $document_id, $slide_name, '');
* Returns additional Java command parameters
* @return string The additional parameters to be used in the Java call
return ' -d woogie "'. $this->base_work_dir. '/'. $this->file_path. '" "'. $this->base_work_dir. $this->created_dir. '/'. $this->file_name. '.html"';
* Formats a page content by reorganising the HTML code a little
* @param string Page header
* @param string Page content
* @return string Formatted page content
// limit the width of the doc
$content = preg_replace("|<body[^>]*>|i","\\0\r\n<div style=\"width:". $max_width. "\">",$content, - 1,$count);
$content = '<body><div style="width:'. $max_width. '">'. $content;
$content = preg_replace('|</body>|i','</div>\\0',$content, - 1, $count);
$content = $content. '</div></body>';
$content = $header. $content;
// resize all the picture to the max_width-10
preg_match_all("|<img[^src]*src=\"([^\"]*)\"[^>]*>|i",$content,$images);
foreach ($images[1] as $key => $image)
// check if the <img tag soon has a width attribute
$defined_width = preg_match("|width=([^\s]*)|i",$images[0][$key], $img_width);
$img_width = $img_width[1];
list ($img_width, $img_height, $type) = getimagesize($this->base_work_dir. $this->created_dir. '/'. $image);
$new_width = $max_width- 10;
if($img_width > $new_width)
$picture_resized = str_ireplace('<img','<img width="'. $new_width. '" ',$images[0][$key]);
$content = str_replace($images[0][$key],$picture_resized,$content);
else if($img_width > $max_width- 10)
$picture_resized = str_ireplace('width='. $img_width,'width="'. ($max_width- 10). '"',$images[0][$key]);
$content = str_replace($images[0][$key],$picture_resized,$content);
* Add documents to the visioconference (to be implemented)
|