openoffice_presentation.class.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php //$id:$
  2. /**
  3. * Defines the OpenOfficeDocument class, which is meant as a conversion
  4. * tool from Office presentations (.ppt, .sxi, .odp, .pptx) to
  5. * learning paths
  6. * @package dokeos.learnpath
  7. * @author Eric Marguin <eric.marguin@dokeos.com>
  8. * @license GNU/GPL - See Dokeos license directory for details
  9. */
  10. /**
  11. * Defines the "OpenofficePresentation" child of class "OpenofficeDocument"
  12. * @package dokeos.learnpath.openofficedocument
  13. */
  14. require_once('openoffice_document.class.php');
  15. class OpenofficePresentation extends OpenofficeDocument {
  16. public $take_slide_name;
  17. function OpenofficePresentation($take_slide_name=false, $course_code=null, $resource_id=null,$user_id=null) {
  18. $this -> take_slide_name = $take_slide_name;
  19. parent::OpenofficeDocument($course_code, $resource_id, $user_id);
  20. }
  21. function make_lp($files=array()) {
  22. global $_course;
  23. $previous = 0;
  24. $i = 0;
  25. if(!is_dir($this->base_work_dir.$this->created_dir))
  26. return false;
  27. foreach($files as $file){
  28. list($slide_name,$file_name) = explode('||',$file); // '||' is used as separator between slide name (with accents) and file name (without accents)
  29. //filename is utf8 encoded, but when we decode, some chars are not translated (like quote &rsquo;).
  30. //so we remove these chars by translating it in htmlentities and the reconvert it in want charset
  31. $slide_name = htmlentities($slide_name,ENT_COMPAT,$this->original_charset);
  32. $slide_name = str_replace('&rsquo;','\'',$slide_name);
  33. $slide_name = mb_convert_encoding($slide_name, api_get_setting('platform_charset'), $this->original_charset);
  34. $slide_name = html_entity_decode($slide_name);
  35. if($this->take_slide_name === true)
  36. {
  37. $slide_name = str_replace('_',' ',$slide_name);
  38. $slide_name = ucfirst($slide_name);
  39. }
  40. else
  41. {
  42. $slide_name = 'slide'.str_repeat('0',2-strlen($i)).$i;
  43. }
  44. $i++;
  45. // add the png to documents
  46. $document_id = add_document($_course,$this->created_dir.'/'.urlencode($file_name),'file',filesize($this->base_work_dir.$this->created_dir.'/'.$file_name),$slide_name);
  47. api_item_property_update($_course,TOOL_DOCUMENT,$document_id,'DocumentAdded',$_SESSION['_uid'],0,0);
  48. // create an html file
  49. $html_file = $file_name.'.html';
  50. $fp = fopen($this->base_work_dir.$this->created_dir.'/'.$html_file, 'w+');
  51. fwrite($fp,
  52. '<html>
  53. <head></head>
  54. <body>
  55. <img src="'.api_get_path(REL_COURSE_PATH).$_course['path'].'/document/'.$this->created_dir.'/'.utf8_encode($file_name).'" />
  56. </body>
  57. </html>');
  58. fclose($fp);
  59. $document_id = add_document($_course,$this->created_dir.'/'.urlencode($html_file),'file',filesize($this->base_work_dir.$this->created_dir.'/'.$html_file),$slide_name);
  60. if ($document_id){
  61. //put the document in item_property update
  62. api_item_property_update($_course,TOOL_DOCUMENT,$document_id,'DocumentAdded',$_SESSION['_uid'],0,0);
  63. $previous = learnpath::add_item(0, $previous, 'document', $document_id, $slide_name, '');
  64. if($this->first_item == 0){
  65. $this->first_item = $previous;
  66. }
  67. }
  68. }
  69. }
  70. function add_command_parameters(){
  71. if(empty($this->slide_width) || empty($this->slide_height))
  72. list($this->slide_width, $this->slide_height) = explode('x',api_get_setting('service_ppt2lp','size'));
  73. return ' -w '.$this->slide_width.' -h '.$this->slide_height.' -d oogie "'.$this->base_work_dir.'/'.$this->file_path.'" "'.$this->base_work_dir.$this->created_dir.'.html"';
  74. }
  75. function set_slide_size($width,$height)
  76. {
  77. $this->slide_width = $width;
  78. $this->slide_height = $height;
  79. }
  80. function add_docs_to_visio ($files=array()){
  81. global $_course;
  82. /* Add Files */
  83. foreach($files as $file){
  84. list($slide_name,$file_name) = explode('||',$file); // '||' is used as separator between slide name (with accents) and file name (without accents)
  85. $slide_name = htmlentities($slide_name,ENT_COMPAT,$this->original_charset);
  86. $slide_name = str_replace('&rsquo;','\'',$slide_name);
  87. $slide_name = mb_convert_encoding($slide_name, api_get_setting('platform_charset'), $this->original_charset);
  88. $slide_name = html_entity_decode($slide_name);
  89. $did = add_document($_course, $this->created_dir.'/'.urlencode($file_name), 'file', filesize($this->base_work_dir.$this->created_dir.'/'.$file_name), $slide_name);
  90. if ($did)
  91. api_item_property_update($_course, TOOL_DOCUMENT, $did, 'DocumentAdded', $_SESSION['_uid'], 0, NULL);
  92. }
  93. }
  94. }
  95. ?>