Maintenance: CommonCartridge: Improve media paths management on import. Accept both $IMS-CC_FILEBASE$ and $1EdTech-CC-FILEBASE$ - refs BT#21709

pull/3943/head^2
Yannick Warnier 1 year ago
parent 825e366b92
commit 193be111cc
  1. 5
      main/common_cartridge/export/src/lib/ccdependencyparser.php
  2. 11
      main/common_cartridge/import/src/converter/Cc13Forum.php
  3. 21
      main/common_cartridge/import/src/converter/Cc13Quiz.php
  4. 3
      main/common_cartridge/import/src/converter/Cc13Resource.php
  5. 10
      main/common_cartridge/import/src/converter/CcEntities.php

@ -85,8 +85,9 @@ function stripUrl($path, $rootDir = '')
*/
function fullPath($path, $dirsep = DIRECTORY_SEPARATOR)
{
$token = '$1EdTech-CC-FILEBASE$';
$path = str_replace($token, '', $path);
$token = '/\$(?:IMS|1EdTech)[-_]CC[-_]FILEBASE\$/';
$path = preg_replace($token, '', $path);
if (is_string($path) && ($path != '')) {
$sep = $dirsep;
$dotDir = '.';

@ -7,8 +7,8 @@ class Cc13Forum extends Cc13Entities
{
public function fullPath($path, $dir_sep = DIRECTORY_SEPARATOR)
{
$token = '$1EdTech-CC-FILEBASE$';
$path = str_replace($token, '', $path);
$token = '/\$(?:IMS|1EdTech)[-_]CC[-_]FILEBASE\$/';
$path = preg_replace($token, '', $path);
if (is_string($path) && ($path != '')) {
$dot_dir = '.';
@ -151,11 +151,14 @@ class Cc13Forum extends Cc13Entities
$images_extensions = ['gif', 'jpeg', 'jpg', 'jif', 'jfif', 'png', 'bmp'];
$fileinfo = pathinfo($filename);
if (empty($rootPath)) {
$rootPath = '';
}
if (in_array($fileinfo['extension'], $images_extensions)) {
return '<img src="$@FILEPHP@$/'.$filename.'" title="'.$fileinfo['basename'].'" alt="'.$fileinfo['basename'].'" /><br />';
return '<img src="'.$rootPath.$filename.'" title="'.$fileinfo['basename'].'" alt="'.$fileinfo['basename'].'" /><br />';
} else {
return '<a href="$@FILEPHP@$/'.$filename.'" title="'.$fileinfo['basename'].'" alt="'.$fileinfo['basename'].'">'.$fileinfo['basename'].'</a><br />';
return '<a href="'.$rootPath.$filename.'" title="'.$fileinfo['basename'].'" alt="'.$fileinfo['basename'].'">'.$fileinfo['basename'].'</a><br />';
}
return '';

@ -53,15 +53,10 @@ class Cc13Quiz extends Cc13Entities
continue;
}
$questionInstance->updateTitle($question['title']);
$questionText = '';
// Replace the path from @@PLUGINFILE@@ to a correct chamilo path
$questionText = str_replace(
'@@PLUGINFILE@@',
'/courses/'.$courseInfo['path'].'/document/moodle',
$questionText
);
$questionInstance->updateTitle(substr(Security::remove_XSS(strip_tags_blacklist($question['title'], ['br', 'p'])), 0, 20));
$questionText = Security::remove_XSS(strip_tags_blacklist($question['title'], ['br', 'p']));
// Replace the path from $1EdTech-CC-FILEBASE$ to a correct chamilo path
$questionText = preg_replace($token, '/courses/'.$courseInfo['path'].'/document', $questionText);
$questionInstance->updateDescription($questionText);
$questionInstance->updateLevel(1);
@ -80,8 +75,8 @@ class Cc13Quiz extends Cc13Entities
$questionWeighting = 0;
foreach ($question['answers'] as $slot => $answerValues) {
$correct = $answerValues['score'] ? (int) $answerValues['score'] : 0;
$answer = $answerValues['title'];
$comment = $answerValues['feedback'];
$answer = Security::remove_XSS(preg_replace($token, '/courses/'.$courseInfo['path'].'/document', $answerValues['title']));
$comment = Security::remove_XSS(preg_replace($token, '/courses/'.$courseInfo['path'].'/document', $answerValues['feedback']));
$weighting = $answerValues['score'];
$weighting = abs($weighting);
if ($weighting > 0) {
@ -110,8 +105,8 @@ class Cc13Quiz extends Cc13Entities
$questionWeighting = 0;
if (is_array($question['answers'])) {
foreach ($question['answers'] as $slot => $answerValues) {
$answer = $answerValues['title'];
$comment = $answerValues['feedback'];
$answer = Security::remove_XSS(preg_replace($token, '/courses/'.$courseInfo['path'].'/document', $answerValues['title']));
$comment = Security::remove_XSS(preg_replace($token, '/courses/'.$courseInfo['path'].'/document', $answerValues['feedback']));
$weighting = $answerValues['score'];
if ($weighting > 0) {
$questionWeighting += $weighting;

@ -178,7 +178,8 @@ class Cc13Resource extends Cc13Entities
if (($rtp !== false) && is_file($rtp)) {
//file is there - we are in business
$strip = str_replace("\\", "/", str_ireplace($rootpath, '', $rtp));
$encoded_file = '$@FILEPHP@$'.str_replace('/', '$@SLASH@$', $strip);
//$encoded_file = '$@FILEPHP@$'.str_replace('/', '$@SLASH@$', $strip);
$encoded_file = $strip;
$searches[] = $resrc->nodeValue;
$replaces[] = $encoded_file;
}

@ -47,9 +47,11 @@ class CcEntities
$protocol = parse_url($attribute_value, PHP_URL_SCHEME);
if (empty($protocol)) {
$attribute_value = str_replace("\$1EdTech-CC-FILEBASE\$", "", $attribute_value);
// The CC standard changed with the renaming of IMS Global to 1stEdTech, so we don't know what we're going to get
$attribute_value = str_replace("\$1EdTech[-_]CC[-_]FILEBASE\$", "", $attribute_value);
$attribute_value = str_replace("\$IMS[-_]CC[-_]FILEBASE\$", "", $attribute_value);
$attribute_value = $this->fullPath($rootPath."/".$attribute_value, "/");
$attribute_value = "\$@FILEPHP@\$"."/".$attribute_value;
//$attribute_value = "\$@FILEPHP@\$"."/".$attribute_value;
}
$element->setAttribute($attribute, $attribute_value);
@ -63,8 +65,8 @@ class CcEntities
public function fullPath($path, $dir_sep = DIRECTORY_SEPARATOR)
{
$token = '$1EdTech-CC-FILEBASE$';
$path = str_replace($token, '', $path);
$token = '/\$(?:IMS|1EdTech)[-_]CC[-_]FILEBASE\$/';
$path = preg_replace($token, '', $path);
if (is_string($path) && ($path != '')) {
$dot_dir = '.';

Loading…
Cancel
Save