|
|
|
@ -32,7 +32,17 @@ $courses = CourseManager::get_courses_list(); |
|
|
|
|
$newUrlAppend = '/NEWFOLDER'; // Url append of new portal |
|
|
|
|
|
|
|
|
|
$slashes = '/../../../../../../../'; |
|
|
|
|
$pathToSearch = '#http(.*)://(.*)'.$slashes.'([^/]+)/(.*)#'; |
|
|
|
|
//$pathToSearch = '#http(.*)://(.*)'.$slashes.'([^/]+)/(.*)/#'; |
|
|
|
|
$pathToSearch = '#(http:\/\/\s*|https:\/\/\s*)?(www\s*)?(?(1)([.]\s*))?(?(2)([.]\s*))?([a-zA-Z0-9.-]{2,256})(\s*[.]\s*)(com|fr|)('.$slashes.')(.*?)/(.*?)/(.*?)/#'; |
|
|
|
|
$pathToReplace = $newUrlAppend.'/courses/${10}/${11}/'; |
|
|
|
|
|
|
|
|
|
// tests |
|
|
|
|
/* |
|
|
|
|
$contents = 'http://something.fr/../../../../../../../courses-lt-marie-chamilo/ABC/document/images/gallery/science.jpg'; |
|
|
|
|
$contents .= '<br />http://something.something.fr/../../../../../../../courses-lt-marie-chamilo/CDE/document/science.jpg'; |
|
|
|
|
$newContent = preg_replace($pathToSearch, $pathToReplace, $contents); |
|
|
|
|
echo $newContent; |
|
|
|
|
exit;*/ |
|
|
|
|
|
|
|
|
|
$courseSysPath = api_get_path(SYS_COURSE_PATH); |
|
|
|
|
foreach ($courses as $course) { |
|
|
|
@ -47,7 +57,7 @@ foreach ($courses as $course) { |
|
|
|
|
foreach ($finder as $file) { |
|
|
|
|
echo $file->getRealPath().'<br />'; |
|
|
|
|
$contents = file_get_contents($file->getRealPath()); |
|
|
|
|
$newContent = preg_replace($pathToSearch, $newUrlAppend.'/courses/${4}', $contents); |
|
|
|
|
$newContent = preg_replace($pathToSearch, $pathToReplace, $contents); |
|
|
|
|
file_put_contents($file->getRealPath(), $newContent); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -57,7 +67,7 @@ foreach ($courses as $course) { |
|
|
|
|
$items = Database::store_result($result); |
|
|
|
|
foreach ($items as $item) { |
|
|
|
|
$id = $item['iid']; |
|
|
|
|
$newContent = preg_replace($pathToSearch, $newUrlAppend.'/courses/${4}', $item['description']); |
|
|
|
|
$newContent = preg_replace($pathToSearch, $pathToReplace, $item['description']); |
|
|
|
|
$newContent = Database::escape_string($newContent); |
|
|
|
|
$sql = "UPDATE c_quiz SET description = '$newContent' WHERE iid = $id"; |
|
|
|
|
Database::query($sql); |
|
|
|
@ -69,10 +79,10 @@ foreach ($courses as $course) { |
|
|
|
|
$items = Database::store_result($result); |
|
|
|
|
foreach ($items as $item) { |
|
|
|
|
$id = $item['iid']; |
|
|
|
|
$description = preg_replace($pathToSearch, $newUrlAppend.'/courses/${4}', $item['description']); |
|
|
|
|
$description = preg_replace($pathToSearch, $pathToReplace, $item['description']); |
|
|
|
|
$description = Database::escape_string($description); |
|
|
|
|
|
|
|
|
|
$question = preg_replace($pathToSearch, $newUrlAppend.'/courses/${4}', $item['question']); |
|
|
|
|
$question = preg_replace($pathToSearch, $pathToReplace, $item['question']); |
|
|
|
|
$question = Database::escape_string($question); |
|
|
|
|
|
|
|
|
|
$sql = "UPDATE c_quiz_question SET |
|
|
|
@ -88,10 +98,10 @@ foreach ($courses as $course) { |
|
|
|
|
$items = Database::store_result($result); |
|
|
|
|
foreach ($items as $item) { |
|
|
|
|
$id = $item['iid']; |
|
|
|
|
$answer = preg_replace($pathToSearch, $newUrlAppend.'/courses/${4}', $item['answer']); |
|
|
|
|
$answer = preg_replace($pathToSearch, $pathToReplace, $item['answer']); |
|
|
|
|
$answer = Database::escape_string($answer); |
|
|
|
|
|
|
|
|
|
$comment = preg_replace($pathToSearch, $newUrlAppend.'/courses/${4}', $item['comment']); |
|
|
|
|
$comment = preg_replace($pathToSearch, $pathToReplace, $item['comment']); |
|
|
|
|
$comment = Database::escape_string($comment); |
|
|
|
|
|
|
|
|
|
$sql = "UPDATE c_quiz_answer SET |
|
|
|
@ -107,7 +117,7 @@ foreach ($courses as $course) { |
|
|
|
|
$items = Database::store_result($result); |
|
|
|
|
foreach ($items as $item) { |
|
|
|
|
$id = $item['iid']; |
|
|
|
|
$text = preg_replace($pathToSearch, $newUrlAppend.'/courses/${4}', $item['intro_text']); |
|
|
|
|
$text = preg_replace($pathToSearch, $pathToReplace, $item['intro_text']); |
|
|
|
|
$text = Database::escape_string($text); |
|
|
|
|
|
|
|
|
|
$sql = "UPDATE c_tool_intro SET |
|
|
|
@ -122,13 +132,58 @@ foreach ($courses as $course) { |
|
|
|
|
$items = Database::store_result($result); |
|
|
|
|
foreach ($items as $item) { |
|
|
|
|
$id = $item['iid']; |
|
|
|
|
$gdescription = preg_replace($pathToSearch, $newUrlAppend.'/courses/${4}', $item['description']); |
|
|
|
|
$gdescription = preg_replace($pathToSearch, $pathToReplace, $item['description']); |
|
|
|
|
$gdescription = Database::escape_string($gdescription); |
|
|
|
|
|
|
|
|
|
$sql = "UPDATE c_glossary SET description = '$gdescription' WHERE iid = $id"; |
|
|
|
|
Database::query($sql); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Updating forums |
|
|
|
|
$sql = "SELECT iid, forum_comment FROM c_forum_forum WHERE c_id = $courseId"; |
|
|
|
|
$result = Database::query($sql); |
|
|
|
|
$items = Database::store_result($result); |
|
|
|
|
foreach ($items as $item) { |
|
|
|
|
$id = $item['iid']; |
|
|
|
|
$text = preg_replace($pathToSearch, $pathToReplace, $item['forum_comment']); |
|
|
|
|
$text = Database::escape_string($text); |
|
|
|
|
|
|
|
|
|
$sql = "UPDATE c_forum_forum SET |
|
|
|
|
forum_comment = '$text' |
|
|
|
|
WHERE iid = $id"; |
|
|
|
|
Database::query($sql); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Updating posts |
|
|
|
|
$sql = "SELECT iid, post_text FROM c_forum_post WHERE c_id = $courseId"; |
|
|
|
|
$result = Database::query($sql); |
|
|
|
|
$items = Database::store_result($result); |
|
|
|
|
foreach ($items as $item) { |
|
|
|
|
$id = $item['iid']; |
|
|
|
|
$text = preg_replace($pathToSearch, $pathToReplace, $item['post_text']); |
|
|
|
|
$text = Database::escape_string($text); |
|
|
|
|
|
|
|
|
|
$sql = "UPDATE c_forum_post SET |
|
|
|
|
post_text = '$text' |
|
|
|
|
WHERE iid = $id"; |
|
|
|
|
Database::query($sql); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Updating forum cats |
|
|
|
|
$sql = "SELECT iid, cat_comment FROM c_forum_category WHERE c_id = $courseId"; |
|
|
|
|
$result = Database::query($sql); |
|
|
|
|
$items = Database::store_result($result); |
|
|
|
|
foreach ($items as $item) { |
|
|
|
|
$id = $item['iid']; |
|
|
|
|
$text = preg_replace($pathToSearch, $pathToReplace, $item['cat_comment']); |
|
|
|
|
$text = Database::escape_string($text); |
|
|
|
|
|
|
|
|
|
$sql = "UPDATE c_forum_category SET |
|
|
|
|
cat_comment = '$text' |
|
|
|
|
WHERE iid = $id"; |
|
|
|
|
Database::query($sql); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
echo "<h4>Path doesn't exist</h4>".'<br />'; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|