additional_webservices.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.webservices
  5. * @author Francis Gonzales
  6. */
  7. require_once '../inc/global.inc.php';
  8. $libpath = api_get_path(LIBRARY_PATH);
  9. /**
  10. * Function to convert from ppt to png
  11. * This function is used from Chamilo Rapid Lesson
  12. *
  13. * @param array $pptData
  14. * @return string
  15. */
  16. function wsConvertPpt($pptData)
  17. {
  18. $fileData = $pptData['file_data'];
  19. $dataInfo = pathinfo($pptData['file_name']);
  20. $fileName = basename($pptData['file_name'], '.' . $dataInfo['extension']);
  21. $fullFileName = $pptData['file_name'];
  22. $tempArchivePath = api_get_path(SYS_ARCHIVE_PATH);
  23. $tempPath = $tempArchivePath . 'wsConvert/' . $fileName . '/';
  24. $tempPathNewFiles = $tempArchivePath . 'wsConvert/' . $fileName . '-n/';
  25. $perms = api_get_permissions_for_new_directories();
  26. if (!is_dir($tempPath)) {
  27. mkdir($tempPath, $perms, true);
  28. }
  29. if (!is_dir($tempPathNewFiles)) {
  30. mkdir($tempPathNewFiles, $perms, true);
  31. }
  32. if (!is_dir($tempPathNewFiles . $fileName)) {
  33. mkdir($tempPathNewFiles . $fileName, $perms, true);
  34. }
  35. $file = base64_decode($fileData);
  36. file_put_contents($tempPath . $fullFileName, $file);
  37. if (IS_WINDOWS_OS) { // IS_WINDOWS_OS has been defined in main_api.lib.php
  38. $converterPath = str_replace('/', '\\', api_get_path(SYS_PATH) . 'main/inc/lib/ppt2png');
  39. $classPath = $converterPath . ';' . $converterPath . '/jodconverter-2.2.2.jar;' . $converterPath . '/jodconverter-cli-2.2.2.jar';
  40. $cmd = 'java -Dfile.encoding=UTF-8 -cp "' . $classPath . '" DokeosConverter';
  41. } else {
  42. $converterPath = api_get_path(SYS_PATH) . 'main/inc/lib/ppt2png';
  43. $classPath = ' -Dfile.encoding=UTF-8 -cp .:jodconverter-2.2.2.jar:jodconverter-cli-2.2.2.jar';
  44. $cmd = 'cd ' . $converterPath . ' && java ' . $classPath . ' DokeosConverter';
  45. }
  46. $cmd .= ' -p ' . api_get_setting('service_ppt2lp', 'port');
  47. $cmd .= ' -w 720 -h 540 -d oogie "' . $tempPath . $fullFileName.'" "' . $tempPathNewFiles . $fileName . '.html"';
  48. $perms = api_get_permissions_for_new_files();
  49. chmod($tempPathNewFiles . $fileName, $perms, true);
  50. $files = array();
  51. $return = 0;
  52. $shell = exec($cmd, $files, $return);
  53. if ($return === 0) {
  54. $images = array();
  55. foreach ($files as $file) {
  56. $imageData = explode('||', $file);
  57. $images[$imageData[1]] = base64_encode(file_get_contents($tempPathNewFiles . $fileName . '/' . $imageData[1]));
  58. }
  59. $data = array(
  60. 'files' => $files,
  61. 'images' => $images
  62. );
  63. deleteDirectory($tempPath);
  64. deleteDirectory($tempPathNewFiles);
  65. return serialize($data);
  66. } else {
  67. deleteDirectory($tempPath);
  68. deleteDirectory($tempPathNewFiles);
  69. return false;
  70. }
  71. }
  72. /**
  73. * @param $directoryPath
  74. * @return bool
  75. */
  76. function deleteDirectory($directoryPath)
  77. {
  78. $files = array_diff(scandir($directoryPath), array('.','..'));
  79. foreach ($files as $file) {
  80. if (is_dir("$directoryPath/$file")) {
  81. deleteDirectory("$directoryPath/$file");
  82. } else {
  83. unlink("$directoryPath/$file");
  84. }
  85. }
  86. return rmdir($directoryPath);
  87. }
  88. $webPath = api_get_path(WEB_PATH);
  89. $webCodePath = api_get_path(WEB_CODE_PATH);
  90. $options = array(
  91. 'uri' => $webPath,
  92. 'location' => $webCodePath . 'webservices/additional_webservices.php'
  93. );
  94. $soapServer = new SoapServer(NULL, $options);
  95. $soapServer->addFunction('wsConvertPpt');
  96. $soapServer->handle();