* @license GNU/GPL - See Dokeos license directory for details */ /** * Defines the "aicc" child of class "learnpath" * @package dokeos.learnpath.aicc */ require_once('openoffice_document.class.php'); class OpenOfficeTextDocument extends OpenofficeDocument { public $split_steps; function OpenofficeTextDocument($split_steps=false, $course_code=null, $resource_id=null,$user_id=null) { $this -> split_steps = $split_steps; parent::OpenofficeDocument($course_code, $resource_id, $user_id); } function make_lp($files=array()){ global $_course; // we get a content where ||page_break|| indicates where the page is broken $content = file_get_contents($this->base_work_dir.$this->created_dir.'/'.$this->file_name.'.html'); // set the charset if necessary $charset = api_get_setting('platform_charset'); if(strcasecmp($charset,'utf-8')!==0) { $content = utf8_decode($content); $content = str_replace('utf-8',$charset,$content); } // set the path to pictures to absolute (so that it can be modified in fckeditor) $content = preg_replace("|src=\"([^\"]*)|i", "src=\"".api_get_path(REL_COURSE_PATH).$_course['path'].'/document'.$this->created_dir."/\\1", $content); list($header, $body) = explode('\r\n"; $style_to_import .= '@import "'.api_get_path(WEB_CODE_PATH).'css/'.$my_style.'/default.css";'."\n"; $style_to_import .= '@import "'.api_get_path(WEB_CODE_PATH).'css/'.$my_style.'/course.css";'."\n"; $style_to_import .= "\r\n"; $header = preg_replace("||i", "\r\n$style_to_import\r\n\\0",$header); // line break before and after picture $header = str_replace('p {','p {clear:both;',$header); $header = str_replace('absolute','relative',$header); switch($this->split_steps) { case 'per_page' : $this -> dealPerPage($header,$body); break; case 'per_chapter' : $this -> dealPerChapter($header,$body); break; } } function dealPerChapter($header, $content){ global $_course; $content = str_replace('||page_break||','',$content); // get all the h1 preg_match_all("|]*>([^(h1)+]*)|is",$content,$matches_temp); //empty the fake chapters $new_index = 0; for ($i=0 ; $i$item_content) { $i++; $page_content = $this->format_page_content($header, $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); fclose($handle); $document_id = add_document($_course,$this->created_dir.'/'.$html_file,'file',filesize($this->base_work_dir.$this->created_dir.'/'.$html_file),$html_file); if ($document_id){ //put the document in item_property update api_item_property_update($_course,TOOL_DOCUMENT,$document_id,'DocumentAdded',$_SESSION['_uid'],0,0); $infos = pathinfo($this->filepath); $slide_name = strip_tags(nl2br($item_title)); $slide_name = str_replace(array("\r\n", "\r", "\n"), "", $slide_name); $slide_name = html_entity_decode($slide_name); $previous = learnpath::add_item(0, $previous, 'document', $document_id, $slide_name, ''); if($this->first_item == 0){ $this->first_item = $previous; } } } } function dealPerPage($header,$body) { // split document to pages $pages = explode('||page_break||',$body); $first_item = 0; foreach($pages as $key=>$page_content){ // for every pages, we create a new file $key +=1; $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); fclose($handle); $document_id = add_document($_course,$this->created_dir.'/'.$html_file,'file',filesize($this->base_work_dir.$this->created_dir.'/'.$html_file),$html_file); if ($document_id){ //put the document in item_property update api_item_property_update($_course,TOOL_DOCUMENT,$document_id,'DocumentAdded',$_SESSION['_uid'],0,0); $infos = pathinfo($this->filepath); $slide_name = 'Page '.str_repeat('0',2-strlen($key)).$key; $previous = learnpath::add_item(0, $previous, 'document', $document_id, $slide_name, ''); if($this->first_item == 0){ $this->first_item = $previous; } } } } function add_command_parameters(){ return ' -d woogie'; } function format_page_content($header, $content) { // limit the width of the doc list($max_width, $max_height) = explode('x',api_get_setting('service_ppt2lp','size')); $content = preg_replace("|]*>|i","\\0\r\n
",$content, -1,$count); if($count < 1) { $content = '
'.$content; } $content = preg_replace('||i','
\\0',$content, -1, $count); if($count < 1) { $content = $content.'
'; } // add the headers $content = $header.$content; // resize all the picture to the max_width-10 preg_match_all("|]*>|i",$content,$images); foreach ($images[1] as $key => $image) { // check if the base_work_dir.$this->created_dir.'/'.$image); $new_width = $max_width-10; if($img_width > $new_width) { $picture_resized = str_ireplace(' $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); } } return $content; } function add_docs_to_visio (){ } } ?>