소스 검색

Webservice to Convert from ppt to Leaning path - refs BT#8441

Francis Gonzales 10 년 전
부모
커밋
7610baf413
2개의 변경된 파일124개의 추가작업 그리고 20개의 파일을 삭제
  1. 20 20
      main/newscorm/openoffice_document.class.php
  2. 104 0
      main/webservices/additional_webservices.php

+ 20 - 20
main/newscorm/openoffice_document.class.php

@@ -133,8 +133,7 @@ abstract class OpenofficeDocument extends learnpath
         } else {
             // get result from webservices
             $result = $this->_get_remote_ppt2lp_files($file);
-            $result = unserialize(base64_decode($result));
-
+            $result = unserialize($result);
             // Save remote images to server
             chmod($this->base_work_dir.$this->created_dir, api_get_permissions_for_new_directories());
             if (!empty($result['images'])) {
@@ -174,7 +173,6 @@ abstract class OpenofficeDocument extends learnpath
      */
     private function _get_remote_ppt2lp_files($file)
     {
-        require_once api_get_path(LIBRARY_PATH) . 'nusoap/nusoap.php';
         // host
         $ppt2lp_host = api_get_setting('service_ppt2lp', 'host');
 
@@ -182,27 +180,29 @@ abstract class OpenofficeDocument extends learnpath
         $secret_key = sha1(api_get_setting('service_ppt2lp', 'ftp_password'));
 
         // client
-        $client = new nusoap_client($ppt2lp_host, true);
-
+        $options = array(
+            'location' => $ppt2lp_host,
+            'uri' => $ppt2lp_host,
+            'trace' => 1,
+            'exception' => 1,
+            'cache_wsdl' => WSDL_CACHE_NONE,
+        );
+        $client = new SoapClient(null, $options);
         $result = '';
-        $err = $client->getError();
-        if (!$err) {
 
-            $file_data = base64_encode(file_get_contents($file['tmp_name']));
-            $file_name = $file['name'];
-            $service_ppt2lp_size = api_get_setting('service_ppt2lp', 'size');
+        $file_data = base64_encode(file_get_contents($file['tmp_name']));
+        $file_name = $file['name'];
+        $service_ppt2lp_size = api_get_setting('service_ppt2lp', 'size');
 
-            $params = array(
-                'secret_key' => $secret_key,
-                'file_data' => $file_data,
-                'file_name' => $file_name,
-                'service_ppt2lp_size' => $service_ppt2lp_size,
-            );
+        $params = array(
+            'secret_key' => $secret_key,
+            'file_data' => $file_data,
+            'file_name' => $file_name,
+            'service_ppt2lp_size' => $service_ppt2lp_size,
+        );
+
+        $result = $client->__call('wsConvertPpt', array('pptData' => $params));
 
-            $result = $client->call('ws_convert_ppt', array('convert_ppt' => $params));
-        } else {
-            return false;
-        }
         return $result;
     }
 

+ 104 - 0
main/webservices/additional_webservices.php

@@ -0,0 +1,104 @@
+<?php
+/* For licensing terms, see /license.txt */
+/**
+ * @package chamilo.webservices
+ * @author Francis Gonzales
+ */
+
+require_once '../inc/global.inc.php';
+$libpath = api_get_path(LIBRARY_PATH);
+require_once $libpath.'fileManage.lib.php';
+require_once $libpath.'fileUpload.lib.php';
+require_once api_get_path(INCLUDE_PATH).'lib/mail.lib.inc.php';
+require_once $libpath.'add_course.lib.inc.php';
+
+
+/**
+ * Function to convert from ppt to png
+ * This function is used from Chamilo Rapid Lesson
+ *
+ * @param array $pptData
+ * @return string
+ */
+function wsConvertPpt($pptData)
+{
+    $fileData = $pptData['file_data'];
+    $dataInfo = pathinfo($pptData['file_name']);
+    $fileName =  basename($pptData['file_name'], '.' . $dataInfo['extension']);
+    $fullFileName = $pptData['file_name'];
+
+    $tempArchivePath = api_get_path(SYS_ARCHIVE_PATH);
+    $tempPath = $tempArchivePath . 'wsConvert/' . $fileName . '/';
+    $tempPathNewFiles = $tempArchivePath . 'wsConvert/' . $fileName . '-n/';
+
+    mkdir($tempPath, 0777, true);
+    mkdir($tempPathNewFiles, 0777, true);
+    mkdir($tempPathNewFiles . $fileName, 0777, true);
+
+    $file = base64_decode($fileData);
+    file_put_contents($tempPath . $fullFileName, $file);
+
+    if (IS_WINDOWS_OS) { // IS_WINDOWS_OS has been defined in main_api.lib.php
+        $converterPath = str_replace('/', '\\', api_get_path(SYS_PATH) . 'main/inc/lib/ppt2png');
+        $classPath = $converterPath . ';' . $converterPath . '/jodconverter-2.2.2.jar;' . $converterPath . '/jodconverter-cli-2.2.2.jar';
+        $cmd = 'java -Dfile.encoding=UTF-8 -cp "' . $classPath . '" DokeosConverter';
+    } else {
+        $converterPath = api_get_path(SYS_PATH) . 'main/inc/lib/ppt2png';
+        $classPath = ' -Dfile.encoding=UTF-8 -cp .:jodconverter-2.2.2.jar:jodconverter-cli-2.2.2.jar';
+        $cmd = 'cd ' . $converterPath . ' && java ' . $classPath . ' DokeosConverter';
+    }
+
+    $cmd .= ' -p ' . api_get_setting('service_ppt2lp', 'port');
+    $cmd .= ' -w 720 -h 540 -d oogie "' . $tempPath . $fullFileName.'"  "' . $tempPathNewFiles . $fileName . '.html"';
+
+    chmod($tempPath, 0777);
+    chmod($tempPathNewFiles, 0777);
+    chmod($tempPathNewFiles . $fileName, 0777, true);
+
+    $files = array();
+    $return = 0;
+    $shell = exec($cmd, $files, $return);
+
+    if ($return === 0) {
+        $images = array();
+        foreach ($files as $file) {
+            $imageData = explode('||', $file);
+            $images[$imageData[1]] = base64_encode(file_get_contents($tempPathNewFiles . $fileName . '/' . $imageData[1]));
+        }
+        $data = array(
+            'files' => $files,
+            'images' => $images
+        );
+
+        deleteDirectory($tempPath);
+        deleteDirectory($tempPathNewFiles);
+
+        return serialize($data);
+    } else {
+        deleteDirectory($tempPath);
+        deleteDirectory($tempPathNewFiles);
+
+        return false;
+    }
+}
+
+function deleteDirectory($directoryPath)
+{
+    $files = array_diff(scandir($directoryPath), array('.','..'));
+    foreach ($files as $file) {
+        (is_dir("$directoryPath/$file")) ? deleteDirectory("$directoryPath/$file") : unlink("$directoryPath/$file");
+    }
+
+    return rmdir($directoryPath);
+}
+
+
+$webPath = api_get_path(WEB_PATH);
+$webCodePath = api_get_path(WEB_CODE_PATH);
+$options = array(
+    'uri' => $webPath,
+    'location' => $webCodePath . 'webservices/additional_webservices.php'
+);
+$soapServer = new SoapServer(NULL, $options);
+$soapServer->addFunction('wsConvertPpt');
+$soapServer->handle();