Minor - Code style. Add Documentation and removed unused code - refs BT#8274

1.9.x
Daniel Barreto 11 years ago
parent dfe4908539
commit 42752cfdcf
  1. 11
      main/document/document.inc.php
  2. 93
      main/document/document.php
  3. 3
      main/inc/global.inc.php
  4. 72
      main/inc/lib/document.lib.php
  5. 6
      main/newscorm/openoffice_document.class.php

@ -629,8 +629,15 @@ function build_edit_icons($document_data, $id, $is_template, $is_read_only = 0,
// nothing to do
} else {
if ($usePpt2lp && $formatType) {
$modify_icons .= '&nbsp;<a class="convertAction" href="#" data-documentId = ' . $document_id . ' data-formatType = ' . $formatType . '>' .
Display::return_icon('convert.png', get_lang('Convert'), array(), ICON_SIZE_SMALL) . '</a>';
$modify_icons .= '&nbsp;<a class="convertAction" href="#" ' .
'data-documentId = ' . $document_id .
' data-formatType = ' . $formatType . '>' .
Display::return_icon(
'convert.png',
get_lang('Convert'),
array(),
ICON_SIZE_SMALL
) . '</a>';
}
}
}

@ -57,10 +57,11 @@ if(
unlink($_SESSION['temp_realpath_image']);
}
$courseInfo = api_get_course_info();
$course_dir = $courseInfo['directory'].'/document';
$course_dir = $courseInfo['directory'] . '/document';
$sys_course_path = api_get_path(SYS_COURSE_PATH);
$base_work_dir = $sys_course_path.$course_dir;
$http_www = api_get_path(WEB_COURSE_PATH).$courseInfo['directory'].'/document';
$base_work_dir = $sys_course_path . $course_dir;
$http_www = api_get_path(WEB_COURSE_PATH) .
$courseInfo['directory'] . '/document';
$document_path = $base_work_dir;
$usePpt2lp = api_get_setting('service_ppt2lp', 'active') == 'true';
@ -415,8 +416,12 @@ switch ($action) {
break;
case 'convertToPdf':
// PDF format as target by default
$formatTarget = $_REQUEST['formatTarget']? strtolower(Security::remove_XSS($_REQUEST['formatTarget'])) : 'pdf';
$formatType = $_REQUEST['formatType']? strtolower(Security::remove_XSS($_REQUEST['formatType'])) : 'text';
$formatTarget = $_REQUEST['formatTarget'] ?
strtolower(Security::remove_XSS($_REQUEST['formatTarget'])) :
'pdf';
$formatType = $_REQUEST['formatType'] ?
strtolower(Security::remove_XSS($_REQUEST['formatType'])) :
'text';
// Get the document data from the ID
$document_info = DocumentManager::get_document_data_by_id(
$document_id,
@ -424,35 +429,75 @@ switch ($action) {
true,
$session_id
);
$file = $sys_course_path.$courseInfo['directory'].'/document'.$document_info['path'];
$file = $sys_course_path . $courseInfo['directory'] .
'/document' . $document_info['path'];
$fileInfo = pathinfo($file);
if ($fileInfo['extension'] == $formatTarget) {
$message = Display::return_message(get_lang('ErrorSameFormat'), 'warning');
} elseif (!(in_array($fileInfo['extension'], DocumentManager::get_jodconverter_extension_list('from', $formatType))) ||
!(in_array($formatTarget, DocumentManager::get_jodconverter_extension_list('to', $formatType)))) {
$message = Display::return_message(get_lang('FormatNotSupported'), 'warning');
$message = Display::return_message(
get_lang('ErrorSameFormat'),
'warning'
);
} elseif (
!(
in_array(
$fileInfo['extension'],
DocumentManager::getJodconverterExtensionList(
'from',
$formatType
)
)
) || !(
in_array(
$formatTarget,
DocumentManager::getJodconverterExtensionList(
'to',
$formatType
)
)
)
) {
$message = Display::return_message(
get_lang('FormatNotSupported'),
'warning'
);
} else {
$convertedFile = $fileInfo['dirname'] . DIRECTORY_SEPARATOR . $fileInfo['filename'] .
'_from_' . $fileInfo['extension'] . '.' . $formatTarget;
$convertedFile = $fileInfo['dirname'] . DIRECTORY_SEPARATOR .
$fileInfo['filename'] . '_from_' . $fileInfo['extension'] .
'.' . $formatTarget;
$convertedTitle = $document_info['title'];
$obj = new OpenofficePresentation(true);
if (file_exists($convertedFile)) {
$message = Display::return_message(get_lang('FileExists'), 'error');
$message = Display::return_message(
get_lang('FileExists'),
'error'
);
} else {
$result = $obj->convertCopyDocument($file, $convertedFile, $convertedTitle);
$result = $obj->convertCopyDocument(
$file,
$convertedFile,
$convertedTitle
);
if (empty($result)) {
$message = Display::return_message(get_lang('CopyFailed'), 'error');
$message = Display::return_message(
get_lang('CopyFailed'),
'error'
);
} else {
$cidReq = Security::remove_XSS($_GET['cidReq']);
$id_session = api_get_session_id();
$gidReq = Security::remove_XSS($_GET['gidReq']);
$file_link = Display::url(
get_lang('SeeFile'),
api_get_path(WEB_CODE_PATH).'document/showinframes.php?'.
'cidReq='.$cidReq.'&amp;id_session='.$id_session.'&amp;'.
'gidReq='.$gidReq.'&amp;id='.current($result)
api_get_path(WEB_CODE_PATH) .
'document/showinframes.php?' . 'cidReq=' . $cidReq .
'&id_session=' . $id_session . '&' .
'gidReq=' . $gidReq . '&id=' . current($result)
);
$message = Display::return_message(
get_lang('CopyMade') . ' ' . $file_link,
'confirmation',
false
);
$message = Display::return_message(get_lang('CopyMade').' '.$file_link, 'confirmation', false);
}
}
}
@ -663,10 +708,11 @@ function convertModal (id, format) {
$("#convertSelect").change(function() {
var formatTarget = $(this).val();
window.location.href = "'.
api_get_self() . '?' . api_get_cidreq() . '&curdirpath=' . $curdirpath .
'&action=convertToPdf&formatTarget='.'" + formatTarget + "&id=" + id + "'.
$req_gid . '&formatType=" + format
;
api_get_self() . '?' . api_get_cidreq() .
'&curdirpath=' . $curdirpath .
'&action=convertToPdf&formatTarget=' .
'" + formatTarget + "&id=" + id + "' .
$req_gid . '&formatType=" + format;
});
$("#convertModal").on("hidden", function(){
$("." + format + "FormatType").hide();
@ -1835,7 +1881,6 @@ if (count($documentAndFolders) > 1) {
$form_action['set_invisible'] = get_lang('SetInvisible');
$form_action['set_visible'] = get_lang('SetVisible');
$form_action['delete'] = get_lang('Delete');
// $form_action['convert'] = get_lang('ConvertFormat');
$portfolio_actions = Portfolio::actions();
foreach ($portfolio_actions as $action) {
$form_action[$action->get_name()] = $action->get_title();

@ -222,9 +222,6 @@ if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) {
array_walk_recursive_limited($_COOKIE, 'stripslashes', true);
array_walk_recursive_limited($_REQUEST, 'stripslashes', true);
}
// Commented because avoid refresh plugin values - refs BT#8274
// $_setting = isset($_SESSION['_setting']) ? $_SESSION['_setting'] : null;
// $_plugins = isset($_SESSION['_plugins']) ? $_SESSION['_plugins'] : null;
// access_url == 1 is the default chamilo location
if ($_configuration['access_url'] != 1) {

@ -3912,15 +3912,58 @@ class DocumentManager
* 'all'
* @return array
*/
public static function get_jodconverter_extension_list($mode, $format)
public static function getJodconverterExtensionList($mode, $format)
{
$extensionList = array();
$extensionListFromText = array('odt', 'sxw', 'rtf', 'doc', 'docx', 'wpd', 'txt');
$extensionListToText = array('pdf', 'odt', 'sxw', 'rtf', 'doc', 'docx', 'txt');
$extensionListFromSpreadsheet = array('ods', 'sxc', 'xls', 'xlsx', 'csv', 'tsv');
$extensionListToSpreadsheet = array('pdf', 'ods', 'sxc', 'xls', 'xlsx', 'csv', 'tsv');
$extensionListFromPresentation = array('odp', 'sxi', 'ppt', 'pptx');
$extensionListToPresentation = array('pdf', 'swf', 'odp', 'sxi', 'ppt', 'pptx');
$extensionListFromText = array(
'odt',
'sxw',
'rtf',
'doc',
'docx',
'wpd',
'txt',
);
$extensionListToText = array(
'pdf',
'odt',
'sxw',
'rtf',
'doc',
'docx',
'txt',
);
$extensionListFromSpreadsheet = array(
'ods',
'sxc',
'xls',
'xlsx',
'csv',
'tsv',
);
$extensionListToSpreadsheet = array(
'pdf',
'ods',
'sxc',
'xls',
'xlsx',
'csv',
'tsv',
);
$extensionListFromPresentation = array(
'odp',
'sxi',
'ppt',
'pptx',
);
$extensionListToPresentation = array(
'pdf',
'swf',
'odp',
'sxi',
'ppt',
'pptx',
);
$extensionListFromDrawing = array('odg');
$extensionListToDrawing = array('svg', 'swf');
@ -3981,12 +4024,25 @@ class DocumentManager
return $extensionList;
}
/**
* Get Format type list by extension and mode
* @param string $mode Mode to search format type list
* @example 'from'
* @example 'to'
* @param string $extension file extension to check file type
* @return array
*/
public static function getFormatTypeListConvertor($mode = 'from', $extension)
{
$formatTypesList = array();
$formatTypes = array('text', 'spreadsheet', 'presentation', 'drawing');
foreach ($formatTypes as $formatType) {
if (in_array($extension, self::get_jodconverter_extension_list($mode, $formatType))) {
if (
in_array(
$extension,
self::getJodconverterExtensionList($mode, $formatType)
)
) {
$formatTypesList[] = $formatType;
}
}

@ -214,9 +214,9 @@ abstract class OpenofficeDocument extends learnpath
/**
* Used to convert copied from document
* @param $originalPath
* @param $convertedPath
* @param string $action_after_conversion
* @param string $originalPath
* @param string $convertedPath
* @param string $convertedTitle
* @return bool
*/
function convertCopyDocument($originalPath, $convertedPath, $convertedTitle){

Loading…
Cancel
Save