Prechádzať zdrojové kódy

[svn r13997] Oogie uses too jodconverter now. The code has been improved.

Eric Marguin 17 rokov pred
rodič
commit
0d2acc2bf8

+ 1 - 1
main/newscorm/learnpath.class.php

@@ -1713,7 +1713,7 @@ class learnpath {
 		
 		if(!empty($_POST['ppt2lp']) && !in_array($extension,array('dll','exe')))
 		{
-			return 'ppt';
+			return 'oogie';
 		}
 		if(!empty($_POST['woogie']) && !in_array($extension,array('dll','exe')))
 		{

+ 7 - 7
main/newscorm/lp_upload.php

@@ -81,15 +81,15 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST'
 			$oAICC->set_maker($maker);
 			$oAICC->set_jslib('aicc_api.php');
 			break;
-		case 'ppt':
-			require_once('presentation.class.php');
-			$o_ppt = new presentation();
-			$first_item_id = $o_ppt -> convert_presentation($_FILES['user_file']);				
+		case 'oogie':
+			require_once('openoffice_presentation.class.php');
+			$o_ppt = new OpenofficePresentation();
+			$first_item_id = $o_ppt -> convert_document($_FILES['user_file']);				
 			break;
 		case 'woogie':
-			require_once('word_document.class.php');
-			$o_doc = new word_document();
-			$first_item_id = $o_doc -> convert_word_document($_FILES['user_file']);				
+			require_once('openoffice_text_document.class.php');
+			$o_doc = new OpenofficeTextDocument();
+			$first_item_id = $o_doc -> convert_document($_FILES['user_file']);				
 			break;
 		case '':
 		default:

+ 113 - 0
main/newscorm/openoffice_document.class.php

@@ -0,0 +1,113 @@
+<?php //$id:$
+/**
+ * Defines the AICC class, which is meant to contain the aicc items (nuclear elements)
+ * @package dokeos.learnpath.aicc
+ * @author	Yannick Warnier <ywarnier@beeznest.org>
+ * @license	GNU/GPL - See Dokeos license directory for details
+ */
+/**
+ * Defines the "aicc" child of class "learnpath"
+ * @package dokeos.learnpath.aicc
+ */
+
+abstract class OpenofficeDocument extends learnpath {
+	
+
+	public $first_item = 0;
+
+	/**
+	 * Class constructor. Based on the parent constructor.
+	 * @param	string	Course code
+	 * @param	integer	Learnpath ID in DB
+	 * @param	integer	User ID
+	 */
+    function OpenofficeDocument($course_code=null,$resource_id=null,$user_id=null) {
+    	if($this->debug>0){error_log('In OogieWoogie::OogieWoogie()',0);}
+    	if(!empty($course_code) and !empty($resource_id) and !empty($user_id))
+    	{
+    		parent::learnpath($course_code, $resource_id, $user_id);
+    	}else{
+    		//do nothing but still build the presentation object
+    	}
+    }
+    
+    function convert_document($file){
+    	
+    	global $_course, $_user, $_configuration;
+    
+    	$this->file_name = (strrpos($file['name'],'.')>0 ? substr($file['name'], 0, strrpos($file['name'],'.')) : $file['name']);
+    	$this->file_name = remove_accents($this->file_name);
+		$this->file_name = replace_dangerous_char($this->file_name,'strict');	
+		$this->file_name = strtolower($this->file_name);
+		
+		$this->file_path = $this->file_name.'.'.pathinfo($file['name'],PATHINFO_EXTENSION);
+		
+		
+		
+		$dir_name = '/'.$this->file_name;
+		
+	
+		//create the directory
+		
+		$this->base_work_dir = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
+		$this->created_dir = create_unexisting_directory($_course,$_user['user_id'],0,0,$this->base_work_dir,$dir_name);
+
+		
+		move_uploaded_file($file['tmp_name'],$this->base_work_dir.'/'.$this->file_path);
+
+		$perm = api_get_setting('permissions_for_new_files');
+		
+		
+		$classpath = '-cp .:ridl.jar:js.jar:juh.jar:jurt.jar:jut.jar:java_uno.jar:java_uno_accessbridge.jar:edtftpj-1.5.2.jar:unoil.jar:commons-cli-1.0.jar:commons-io-1.3.1.jar:jodconverter-2.2.0.jar:jodconverter-cli-2.2.0.jar';
+		if(strpos($_ENV['OS'],'Windows') !== false)
+		{
+			$classpath = str_replace(':',';',$classpath);
+		}
+		if(strpos($_ENV['OS'],'Windows') !== false)
+		{
+			$cmd = 'cd '.str_replace('/','\\',api_get_path(SYS_PATH).'main/inc/lib/ppt2png ').$classpath.' DokeosConverter';
+		}
+		else
+		{
+			$cmd = 'cd '.api_get_path(SYS_PATH).'main/inc/lib/ppt2png && java '.$classpath.' DokeosConverter';
+		}
+		$cmd .=  ' -p 2002';		
+		
+		// call to the function implemented by child
+		$cmd .= $this -> add_command_parameters();	
+			
+		$cmd .= ' "'.$this->base_work_dir.'/'.$this->file_path.'" "'.$this->base_work_dir.$this->created_dir.'/'.$this->file_name.'.html"';
+
+		// to allow openoffice to manipulate docs.
+		chmod ($this->base_work_dir.$this->created_dir,0777);
+		chmod($this->base_work_dir.'/'.$this->file_path,0777);
+		
+		$shell = exec($cmd, $files, $return);
+		
+		if($return != 0) { //if the java application returns an error code
+		
+			DocumentManager::delete_document($_course, $dir_name, $this->base_work_dir);	 
+			return false;   
+				
+	    }
+	    
+		// create lp
+		$this->lp_id = learnpath::add_lp($_course['id'], $this->file_name,'','guess','manual');
+		
+		// call to the function implemented by child
+		$this -> make_lp($files);
+				
+	    $perm = api_get_setting('permissions_for_new_directories');
+		$perm = octdec(!empty($perm)?$perm:0770);
+		chmod ($this->base_work_dir.$this->created_dir,$perm);
+	    return $this->first_item;   	
+	    
+    }
+
+    
+    abstract function make_lp();
+    abstract function add_command_parameters();
+   
+		
+}
+?>

+ 68 - 0
main/newscorm/openoffice_presentation.class.php

@@ -0,0 +1,68 @@
+<?php //$id:$
+/**
+ * Defines the AICC class, which is meant to contain the aicc items (nuclear elements)
+ * @package dokeos.learnpath.aicc
+ * @author	Yannick Warnier <ywarnier@beeznest.org>
+ * @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 OpenofficePresentation extends OpenofficeDocument {
+
+    
+    function make_lp($files = array()) {
+    
+    	global $_course;
+   
+		$previous = 0;
+		$i = 0;
+		foreach($files as $file){
+			$i++;		
+			
+			// add the png to documents
+			$document_id = add_document($_course,$this->created_dir.'/'.$file,'file',filesize($this->base_work_dir.$this->created_dir.'/'.$file),$file);
+			api_item_property_update($_course,TOOL_DOCUMENT,$document_id,'DocumentAdded',$_SESSION['_uid'],0,0);
+			
+			
+			// create an html file
+			$html_file = $file.'.html';
+			$fp = fopen($this->base_work_dir.$this->created_dir.'/'.$html_file, 'w+');
+			
+			fwrite($fp,
+					'<html>
+					<head></head>
+					<body>
+						<img src="'.$this->file_name.'/'.$file.'" />
+					</body>
+					</html>');
+			fclose($fp);
+			$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($file);
+				$slide_name = 'slide'.str_repeat('0',2-strlen($i)).$i;
+				$previous = learnpath::add_item(0, $previous, 'document', $document_id, $slide_name, '');
+				if($this->first_item == 0){
+					$this->first_item = $previous;
+				}
+			}
+		}
+    }
+    
+    function add_command_parameters(){
+    
+    	list($slide_width, $slide_height) = explode('x',api_get_setting('service_ppt2lp','size'));
+    	return " -w $slide_width -h $slide_height -d oogie";
+    
+    }
+	    
+		
+}
+?>

+ 137 - 0
main/newscorm/openoffice_text_document.class.php

@@ -0,0 +1,137 @@
+<?php //$id:$
+/**
+ * Defines the AICC class, which is meant to contain the aicc items (nuclear elements)
+ * @package dokeos.learnpath.aicc
+ * @author	Yannick Warnier <ywarnier@beeznest.org>
+ * @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 {
+	
+
+    
+    function make_lp($files=array()){
+    	
+		global $_course;
+		
+		$content = file_get_contents($this->base_work_dir.$this->created_dir.'/'.$this->file_name.'.html');
+		
+		
+		// we get a content where ||page_break|| indicates where the page is broken
+
+		list($header, $body) = explode('<BODY',$content);
+
+		$body = '<BODY'.$body;
+		
+		
+		$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, $path_to_folder)
+    {
+    	
+		// Tidy
+		$tidy = new tidy;
+		$config = array(
+		       'indent'         => true,
+		       'output-xhtml'   => true,
+		       'wrap'           => 200,
+		       'clean'           => true,
+		       'bare'			=> true);
+		$tidy->parseString($header.$content, $config, 'utf8');		
+		$tidy->cleanRepair();
+		$content = $tidy;
+		
+		// limit the width of the doc
+		$max_width = '720px';
+		$content = preg_replace("|<body[^>]*>|","\\0\r\n<div style=\"width:".$max_width."\">",$content);
+		$content = str_replace('</body>','</div></body>',$content);
+		
+		// line break before and after picture
+		$content = str_replace('p {','p {clear:both;',strtolower($content));
+		
+		// dokeos styles
+		$my_style = api_get_setting('stylesheets');
+		if(empty($my_style)){$my_style = 'default';}
+		$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";
+		
+		$content = str_replace('/*<![cdata[*/','/*<![cdata[*/ '.$style_to_import,$content);
+		
+		$content = str_replace('absolute','relative',$content);
+		
+		/*
+		// resize all the picture to the max_width-10
+		preg_match_all("|<img src=\"([^\"]*)\"|",strtolower($content),$images);
+		
+		foreach ($images[1] as $image)
+		{
+			list($img_width, $img_height, $type) = getimagesize($path_to_folder.'/'.$image);
+			
+			$new_width = $max_width-10;
+			if($img_width > $new_width)
+			{
+				$new_height = round($new_width/$img_width*$img_height);
+				
+				include_once (api_get_path(LIBRARY_PATH).'image.lib.php');
+				$src = imagecreatefromgif($path_to_folder.'/'.$image);  
+				$dstImg = imagecreatetruecolor($new_width, $new_height);  
+				 
+				$white = imagecolorallocate($dstImg, 255, 255, 255);  
+				 
+				imagefill($dstImg, 0, 0, $white);  
+				imageColorTransparent($dstImg, $white);  
+				imagecopyresampled($dstImg, $src, 0, 0, 0, 0, $new_width, $new_height, $img_width, $img_height);  
+				 
+				imagegif($dstImg,$path_to_folder.'/2'.$image);
+			}
+		}
+		*/
+		
+    	return $content;
+    	
+    }
+   
+		
+}
+?>

+ 0 - 149
main/newscorm/presentation.class.php

@@ -1,149 +0,0 @@
-<?php //$id:$
-/**
- * Defines the AICC class, which is meant to contain the aicc items (nuclear elements)
- * @package dokeos.learnpath.aicc
- * @author	Yannick Warnier <ywarnier@beeznest.org>
- * @license	GNU/GPL - See Dokeos license directory for details
- */
-/**
- * Defines the "aicc" child of class "learnpath"
- * @package dokeos.learnpath.aicc
- */
-
-class presentation extends learnpath {
-
-	/**
-	 * Class constructor. Based on the parent constructor.
-	 * @param	string	Course code
-	 * @param	integer	Learnpath ID in DB
-	 * @param	integer	User ID
-	 */
-    function presentation($course_code=null,$resource_id=null,$user_id=null) {
-    	if($this->debug>0){error_log('In presentation::presentation()',0);}
-    	if(!empty($course_code) and !empty($resource_id) and !empty($user_id))
-    	{
-    		parent::learnpath($course_code, $resource_id, $user_id);
-    	}else{
-    		//do nothing but still build the presentation object
-    	}
-    }
-    
-    function convert_presentation($file){
-    	
-    	global $_course, $_user, $_configuration;
-    
-    	$file_name = (strrpos($file['name'],'.')>0 ? substr($file['name'], 0, strrpos($file['name'],'.')) : $file['name']);
-    	$file_extension = (strrpos($file['name'],'.')>0 ? substr($file['name'], strrpos($file['name'],'.'),10) : '');
-    	
-    	$learnpath_name = $file_name;
-    	$file_name = remove_accents($file_name);
-		$file_name = replace_dangerous_char($file_name,'strict');	
-		$file_name = strtolower($file_name);
-		
-		$file['name'] = $file_name.$file_extension;
-		
-		
-		$dir_name = '/'.$file_name.'_dir';
-		
-		
-		// get properties of ppt file
-		$document_datas = DocumentManager::get_all_document_data($_course, $file);
-		$to_group_id = (empty($document_datas['to_group_id'])) ? 0 : $document_datas['to_group_id'];
-		$to_user_id = (empty($document_datas['to_user_id'])) ? null : $document_datas['to_user_id'];
-	
-		//create the directory
-		
-		$base_work_dir = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
-		$created_dir = create_unexisting_directory($_course,$_user['user_id'],$to_group_id,$to_user_id,$base_work_dir,$dir_name);
-		
-		
-		move_uploaded_file($file['tmp_name'],$base_work_dir.'/'.$file['name']);
-		$file = $base_work_dir.'/'.$file['name'];
-		$perm = api_get_setting('permissions_for_new_files');
-		$perm = octdec(!empty($perm)?$perm:'0660');
-		chmod($file,$perm);
-		
-		
-		/*
-		 * exec java application
-		 * the parameters of the program are :
-		 * - javacommand on this server ;
-		 * - host where openoffice is running;
-		 * - port with which openoffice is listening
-		 * - file to convert
-		 * - folder where put the slides
-		 * - ftppassword if required
-		 * The program fills $files with the list of slides created
-		 */
-		$classpath = '-cp .:ridl.jar:js.jar:juh.jar:jurt.jar:jut.jar:java_uno.jar:java_uno_accessbridge.jar:edtftpj-1.5.2.jar:unoil.jar';
-		if(strpos($_ENV['OS'],'Windows') !== false)
-		{
-			$classpath = str_replace(':',';',$classpath);
-		}
-		list($slide_width, $slide_height) = explode('x',api_get_setting('service_ppt2lp','size'));
-		
-		if(strpos($_ENV['OS'],'Windows') !== false)
-		{
-			$cmd = 'cd '.str_replace('/','\\',api_get_path(SYS_PATH)).'main/inc/lib/ppt2png && java '.$classpath.' DocumentConverter '.api_get_setting('service_ppt2lp','host').' 2002'.' "'.$file.'" "'.$base_work_dir.$created_dir.'"'.' '.$slide_width.' '.$slide_height.' '.api_get_setting('service_ppt2lp','user').' '.api_get_setting('service_ppt2lp','ftp_password');
-		}
-		else
-		{
-			$cmd = 'cd '.api_get_path(SYS_PATH).'main/inc/lib/ppt2png && java '.$classpath.' DocumentConverter '.api_get_setting('service_ppt2lp','host').' 2002'.' "'.$file.'" "'.$base_work_dir.$created_dir.'"'.' '.$slide_width.' '.$slide_height.' '.api_get_setting('service_ppt2lp','user').' '.api_get_setting('service_ppt2lp','ftp_password');
-		}
-		chmod ($base_work_dir.$created_dir,0777);
-		$shell = exec($cmd, $files, $return);
-		
-		chmod ($base_work_dir.$created_dir,0755);
-		if($return != 0) { //if the java application returns an error code
-			DocumentManager::delete_document($_course, $dir_name, $base_work_dir);	 
-			return false;   	
-	    }
-	    else {
-			// create lp
-			
-			$this->lp_id = learnpath::add_lp($_course['id'], $learnpath_name,'','guess','manual');
-			$previous = 0;
-			$i = 0;
-			$first_item = 0;
-			foreach($files as $file){
-				$i++;
-				
-				
-				// add the png to documents
-				$document_id = add_document($_course,$created_dir.'/'.$file,'file',filesize($base_work_dir.$created_dir.'/'.$file),$file);
-				api_item_property_update($_course,TOOL_DOCUMENT,$document_id,'DocumentAdded',$_SESSION['_uid'],$to_group_id,$to_user_id);
-				
-				
-				// create an html file
-				$html_file = $file.'.html';
-				$fp = fopen($base_work_dir.$created_dir.'/'.$html_file, 'w+');
-				
-				fwrite($fp,
-						'<html>
-						<head></head>
-						<body>
-							<img src="./'.$file.'" />
-						</body>
-						</html>');
-				fclose($fp);
-				$document_id = add_document($_course,$created_dir.'/'.$html_file,'file',filesize($base_work_dir.$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'],$to_group_id,$to_user_id);
-					
-					$infos = pathinfo($file);
-					$slide_name = 'slide'.str_repeat('0',2-strlen($i)).$i;
-					$previous = learnpath::add_item(0, $previous, 'document', $document_id, $slide_name, '');
-					if($first_item == 0){
-						$first_item = $previous;
-					}
-				}
-			}
-	    }
-	    return $first_item;   	
-	    
-    }
-		
-}
-?>

+ 0 - 217
main/newscorm/word_document.class.php

@@ -1,217 +0,0 @@
-<?php //$id:$
-/**
- * Defines the AICC class, which is meant to contain the aicc items (nuclear elements)
- * @package dokeos.learnpath.aicc
- * @author	Yannick Warnier <ywarnier@beeznest.org>
- * @license	GNU/GPL - See Dokeos license directory for details
- */
-/**
- * Defines the "aicc" child of class "learnpath"
- * @package dokeos.learnpath.aicc
- */
-
-class word_document extends learnpath {
-	
-
-	/**
-	 * Class constructor. Based on the parent constructor.
-	 * @param	string	Course code
-	 * @param	integer	Learnpath ID in DB
-	 * @param	integer	User ID
-	 */
-    function word_document($course_code=null,$resource_id=null,$user_id=null) {
-    	if($this->debug>0){error_log('In word_document::word_document()',0);}
-    	if(!empty($course_code) and !empty($resource_id) and !empty($user_id))
-    	{
-    		parent::learnpath($course_code, $resource_id, $user_id);
-    	}else{
-    		//do nothing but still build the presentation object
-    	}
-    }
-    
-    function convert_word_document($file){
-    	
-    	global $_course, $_user, $_configuration;
-    
-    	$file_name = (strrpos($file['name'],'.')>0 ? substr($file['name'], 0, strrpos($file['name'],'.')) : $file['name']);
-    	$file_extension = (strrpos($file['name'],'.')>0 ? substr($file['name'], strrpos($file['name'],'.'),10) : '');
-    	
-    	
-		$learnpath_name = $file_name;
-    	$file_name = remove_accents($file_name);
-		$file_name = replace_dangerous_char($file_name,'strict');	
-		$file_name = strtolower($file_name);
-		
-		$file['name'] = $file_name.$file_extension;
-		
-		
-		
-		$dir_name = '/'.$file_name;
-		
-		
-		// get properties of doc file
-		$document_datas = DocumentManager::get_all_document_data($_course, $file);
-		$to_group_id = (empty($document_datas['to_group_id'])) ? 0 : $document_datas['to_group_id'];
-		$to_user_id = (empty($document_datas['to_user_id'])) ? null : $document_datas['to_user_id'];
-	
-		//create the directory
-		
-		$base_work_dir = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
-		$created_dir = create_unexisting_directory($_course,$_user['user_id'],$to_group_id,$to_user_id,$base_work_dir,$dir_name);
-
-		
-		move_uploaded_file($file['tmp_name'],$base_work_dir.'/'.$file['name']);
-		$file = $base_work_dir.'/'.$file['name'];
-
-		$perm = api_get_setting('permissions_for_new_files');
-		
-		
-		$classpath = '-cp .:ridl.jar:js.jar:juh.jar:jurt.jar:jut.jar:java_uno.jar:java_uno_accessbridge.jar:edtftpj-1.5.2.jar:unoil.jar:commons-cli-1.0.jar:commons-io-1.3.1.jar:jodconverter-2.2.0.jar:jodconverter-cli-2.2.0.jar';
-		if(strpos($_ENV['OS'],'Windows') !== false)
-		{
-			$classpath = str_replace(':',';',$classpath);
-		}
-		if(strpos($_ENV['OS'],'Windows') !== false)
-		{
-			$cmd = 'cd '.str_replace('/','\\',api_get_path(SYS_PATH).'main/inc/lib/ppt2png ').$classpath.' DokeosConverter -p 2002 -d woogie "'.$file.'" "'.$base_work_dir.$created_dir.'/'.$file_name.'.html"';
-		}
-		else
-		{
-			$cmd = 'cd '.api_get_path(SYS_PATH).'main/inc/lib/ppt2png && java '.$classpath.' DokeosConverter -p 2002 -d woogie "'.$file.'" "'.$base_work_dir.$created_dir.'/'.$file_name.'.html"';
-		}
-		
-		// to allow openoffice to manipulate docs.
-		chmod ($base_work_dir.$created_dir,0777);
-		chmod($file,0777);
-
-		$shell = exec($cmd, $files, $return);
-		
-		if($return != 0) { //if the java application returns an error code
-		
-			DocumentManager::delete_document($_course, $dir_name, $base_work_dir);	 
-			return false;   	
-	    }
-	    else {
-			// create lp
-			
-			$this->lp_id = learnpath::add_lp($_course['id'], $learnpath_name,'','guess','manual');
-			$content = file_get_contents($base_work_dir.$created_dir.'/'.$file_name.'.html');
-			
-			
-			// we get a content where ||page_break|| indicates where the page is broken
-
-			list($header, $body) = explode('<BODY',$content);
-
-			$body = '<BODY'.$body;
-			
-			
-			$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, $base_work_dir.$created_dir);
-				$html_file = $created_dir.'-'.$key.'.html';
-				$handle = fopen($base_work_dir.$created_dir.'/'.$html_file,'w+');
-				fwrite($handle, $page_content);
-				fclose($handle);
-				
-				$document_id = add_document($_course,$created_dir.'/'.$html_file,'file',filesize($base_work_dir.$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'],$to_group_id,$to_user_id);
-					
-					$infos = pathinfo($file);
-					$slide_name = 'Page '.str_repeat('0',2-strlen($key)).$key;
-					$previous = learnpath::add_item(0, $previous, 'document', $document_id, $slide_name, '');
-					if($first_item == 0){
-						$first_item = $previous;
-					}
-				}
-			}
-			$perm = api_get_setting('permissions_for_new_files');
-			$perm = octdec(!empty($perm)?$perm:0770);
-			chmod($file,$perm);
-			
-	    }
-	    $perm = api_get_setting('permissions_for_new_directories');
-		$perm = octdec(!empty($perm)?$perm:0770);
-		chmod ($base_work_dir.$created_dir,$perm);
-	    return $first_item;   	
-	    
-    }
-    
-    
-    function format_page_content($header, $content, $path_to_folder)
-    {
-    	
-		// Tidy
-		$tidy = new tidy;
-		$config = array(
-		       'indent'         => true,
-		       'output-xhtml'   => true,
-		       'wrap'           => 200,
-		       'clean'           => true,
-		       'bare'			=> true);
-		$tidy->parseString($header.$content, $config, 'utf8');		
-		$tidy->cleanRepair();
-		$content = $tidy;
-		
-		// limit the width of the doc
-		$max_width = '720px';
-		$content = preg_replace("|<body[^>]*>|","\\0\r\n<div style=\"width:".$max_width."\">",$content);
-		$content = str_replace('</body>','</div></body>',$content);
-		
-		// line break before and after picture
-		$content = str_replace('p {','p {clear:both;',strtolower($content));
-		
-		// dokeos styles
-		$my_style = api_get_setting('stylesheets');
-		if(empty($my_style)){$my_style = 'default';}
-		$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";
-		
-		$content = str_replace('/*<![cdata[*/','/*<![cdata[*/ '.$style_to_import,$content);
-		
-		$content = str_replace('absolute','relative',$content);
-		
-		/*
-		// resize all the picture to the max_width-10
-		preg_match_all("|<img src=\"([^\"]*)\"|",strtolower($content),$images);
-		
-		foreach ($images[1] as $image)
-		{
-			list($img_width, $img_height, $type) = getimagesize($path_to_folder.'/'.$image);
-			
-			$new_width = $max_width-10;
-			if($img_width > $new_width)
-			{
-				$new_height = round($new_width/$img_width*$img_height);
-				
-				include_once (api_get_path(LIBRARY_PATH).'image.lib.php');
-				$src = imagecreatefromgif($path_to_folder.'/'.$image);  
-				$dstImg = imagecreatetruecolor($new_width, $new_height);  
-				 
-				$white = imagecolorallocate($dstImg, 255, 255, 255);  
-				 
-				imagefill($dstImg, 0, 0, $white);  
-				imageColorTransparent($dstImg, $white);  
-				imagecopyresampled($dstImg, $src, 0, 0, 0, 0, $new_width, $new_height, $img_width, $img_height);  
-				 
-				imagegif($dstImg,$path_to_folder.'/2'.$image);
-			}
-		}
-		*/
-		
-    	return $content;
-    	
-    }
-   
-		
-}
-?>