123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328 |
- <?php
- abstract class OpenofficeDocument extends learnpath
- {
- public $first_item = 0;
- public $original_charset = 'utf-8';
- public $original_locale = 'en_US.UTF-8';
-
- public function __construct($course_code = null, $resource_id = null, $user_id = null)
- {
- if ($this->debug > 0) {
- error_log('In OpenofficeDocument::OpenofficeDocument()', 0);
- }
- if (!empty($course_code) && !empty($resource_id) && !empty($user_id)) {
- parent::__construct($course_code, $resource_id, $user_id);
- }
- }
-
- public function convert_document($file, $action_after_conversion = 'make_lp')
- {
- $_course = api_get_course_info();
- $this->file_name = pathinfo($file['name'], PATHINFO_FILENAME);
-
- $result = $this->generate_lp_folder($_course, $this->file_name);
-
- $this->base_work_dir = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
-
- $this->created_dir = substr($result['dir'], 0, strlen($result['dir']) -1);
- $this->file_path = $this->created_dir.'/'.api_replace_dangerous_char($file['name']);
-
-
- $ppt2lp_host = api_get_setting('service_ppt2lp', 'host');
- if ($ppt2lp_host == 'localhost') {
- move_uploaded_file($file['tmp_name'], $this->base_work_dir.'/'.$this->file_path);
-
- $perm = api_get_setting('permissions_for_new_files');
- if (IS_WINDOWS_OS) {
- $converter_path = str_replace('/', '\\', api_get_path(SYS_PATH) . 'main/inc/lib/ppt2png');
- $class_path = $converter_path . ';' . $converter_path . '/jodconverter-2.2.2.jar;' . $converter_path . '/jodconverter-cli-2.2.2.jar';
-
- $cmd = 'java -Dfile.encoding=UTF-8 -cp "' . $class_path . '" DokeosConverter';
- } else {
- $converter_path = api_get_path(SYS_PATH) . 'main/inc/lib/ppt2png';
-
- $class_path = ' -Dfile.encoding=UTF-8 -cp .:jodconverter-2.2.2.jar:jodconverter-cli-2.2.2.jar';
- $cmd = 'cd ' . $converter_path . ' && java ' . $class_path . ' DokeosConverter';
- }
- $cmd .= ' -p ' . api_get_setting('service_ppt2lp', 'port');
-
- $cmd .= $this->add_command_parameters();
-
- @chmod($this->base_work_dir, 0777);
- @chmod($this->base_work_dir.$this->created_dir, 0777);
- @chmod($this->base_work_dir.$this->file_path, 0777);
- $locale = $this->original_locale;
- putenv('LC_ALL=' . $locale);
- $files = array();
- $return = 0;
- $shell = exec($cmd, $files, $return);
- if ($return != 0) {
- switch ($return) {
-
- case 1: $this->error = get_lang('CannotConnectToOpenOffice');
- break;
-
- case 2: $this->error = get_lang('OogieConversionFailed');
- break;
-
- case 255: $this->error = get_lang('OogieUnknownError');
- break;
- }
- DocumentManager::delete_document($_course, $this->created_dir, $this->base_work_dir);
- return false;
- }
- } else {
-
- $result = $this->_get_remote_ppt2lp_files($file);
- $result = unserialize($result);
-
- chmod($this->base_work_dir.$this->created_dir, api_get_permissions_for_new_directories());
- if (!empty($result['images'])) {
- foreach ($result['images'] as $image => $img_data) {
- $image_path = $this->base_work_dir.$this->created_dir;
- @file_put_contents($image_path . '/' . $image, base64_decode($img_data));
- @chmod($image_path . '/' . $image, 0777);
- }
- }
-
- $files = $result['files'];
- }
- if (!empty($files)) {
-
- $this->lp_id = learnpath::add_lp($_course['id'], $this->file_name, '', 'guess', 'manual');
-
- switch ($action_after_conversion) {
- case 'make_lp':
- $this->make_lp($files);
- break;
- case 'add_docs_to_visio':
- $this->add_docs_to_visio($files);
- break;
- }
- chmod($this->base_work_dir, api_get_permissions_for_new_directories());
- }
- return $this->first_item;
- }
-
- private function _get_remote_ppt2lp_files($file)
- {
-
- $ppt2lp_host = api_get_setting('service_ppt2lp', 'host');
-
- $secret_key = sha1(api_get_setting('service_ppt2lp', 'ftp_password'));
-
- $options = array(
- 'location' => $ppt2lp_host,
- 'uri' => $ppt2lp_host,
- 'trace' => 1,
- 'exception' => 1,
- 'cache_wsdl' => WSDL_CACHE_NONE,
- );
- $client = new SoapClient(null, $options);
- $result = '';
- $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,
- );
- $result = $client->__call('wsConvertPpt', array('pptData' => $params));
- return $result;
- }
- abstract function make_lp();
- abstract function add_docs_to_visio();
- abstract function add_command_parameters();
-
- function convertCopyDocument($originalPath, $convertedPath, $convertedTitle)
- {
- $_course = api_get_course_info();
- $ids = array();
- $originalPathInfo = pathinfo($originalPath);
- $convertedPathInfo = pathinfo($convertedPath);
- $this->base_work_dir = $originalPathInfo['dirname'];
- $this->file_path = $originalPathInfo['basename'];
- $this->created_dir = $convertedPathInfo['basename'];
- $ppt2lpHost = api_get_setting('service_ppt2lp', 'host');
- $permissionFile = api_get_permissions_for_new_files();
- $permissionFolder = api_get_permissions_for_new_directories();
- if (file_exists($this->base_work_dir . '/' . $this->created_dir)) {
- return $ids;
- }
- if ($ppt2lpHost == 'localhost') {
- if (IS_WINDOWS_OS) {
- $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 -jar "' . $classPath . '/jodconverter-2.2.2.jar"';
- } else {
- $converterPath = api_get_path(SYS_PATH) . 'main/inc/lib/ppt2png';
- $classPath = ' -Dfile.encoding=UTF-8 -jar jodconverter-cli-2.2.2.jar';
- $cmd = 'cd ' . $converterPath . ' && java ' . $classPath . ' ';
- }
- $cmd .= ' -p ' . api_get_setting('service_ppt2lp', 'port');
-
- $cmd .= ' "' . $this->base_work_dir . '/' . $this->file_path . '" "' . $this->base_work_dir . '/' . $this->created_dir . '"';
-
- @chmod($this->base_work_dir, $permissionFolder);
- @chmod($this->base_work_dir . '/' . $this->file_path, $permissionFile);
- $locale = $this->original_locale;
- putenv('LC_ALL=' . $locale);
- $files = array();
- $return = 0;
- $shell = exec($cmd, $files, $return);
-
- @chown($this->base_work_dir . '/' . $this->created_dir, 'www-data');
- @chmod($this->base_work_dir . '/' . $this->created_dir, $permissionFile);
- if ($return != 0) {
- switch ($return) {
-
- case 1: $this->error = get_lang('CannotConnectToOpenOffice');
- break;
-
- case 2: $this->error = get_lang('OogieConversionFailed');
- break;
-
- case 255: $this->error = get_lang('OogieUnknownError');
- break;
- }
- DocumentManager::delete_document($_course, $this->created_dir, $this->base_work_dir);
- return false;
- }
- } else {
-
- }
- if (file_exists($this->base_work_dir . '/' . $this->created_dir)) {
-
- $ids[] = add_document(
- $_course,
- '/' . $this->created_dir,
- 'file',
- filesize($this->base_work_dir . '/' . $this->created_dir),
- $convertedTitle,
- sprintf(
- get_lang('ConvertedFromXToY'),
- strtoupper($originalPathInfo['extension']),
- strtoupper($convertedPathInfo['extension'])
- ),
- 0,
- true,
- null,
- api_get_session_id()
- );
- chmod($this->base_work_dir, $permissionFolder);
- }
- return $ids;
- }
- }
|