Skip to content

Commit 0b87c0d

Browse files
committed
Webservice: Add subscribe_course_to_session_from_extra_field WS - refs BT#22302
2 parents 9724567 + 0dc2f45 commit 0b87c0d

23 files changed

+643
-168
lines changed

index.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,9 @@
195195
$controller->tpl->assign('notice_block', $controller->return_notice());
196196
$controller->tpl->assign('help_block', $controller->return_help());
197197
$controller->tpl->assign('student_publication_block', $controller->studentPublicationBlock());
198-
$controller->tpl->assign('skills_block', $controller->returnSkillLinks());
198+
if (!api_is_anonymous() && !api_user_is_login()) {
199+
$controller->tpl->assign('skills_block', $controller->returnSkillLinks());
200+
}
199201

200202
if (api_is_anonymous()) {
201203
$controller->tpl->setLoginBodyClass();

main/blog/blog_admin.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
}
1919

2020
$origin = api_get_origin();
21-
$action = isset($_GET['action']) ? $_GET['action'] : '';
21+
$action = $_GET['action'] ?? '';
2222

2323
if (api_is_allowed_to_edit()) {
2424
$nameTools = get_lang('blog_management');
@@ -58,11 +58,14 @@
5858
echo Display::return_message(get_lang('BlogEdited'), 'confirmation');
5959
}
6060
}
61-
if (isset($_GET['action']) && $_GET['action'] == 'visibility') {
61+
62+
$isValidToken = Security::check_token('get', null, 'blog');
63+
64+
if ($action == 'visibility' && $isValidToken) {
6265
Blog::changeBlogVisibility(intval($_GET['blog_id']));
6366
echo Display::return_message(get_lang('VisibilityChanged'), 'confirmation');
6467
}
65-
if (isset($_GET['action']) && $_GET['action'] == 'delete') {
68+
if ($action == 'delete' && $isValidToken) {
6669
Blog::deleteBlog(intval($_GET['blog_id']));
6770
echo Display::return_message(get_lang('BlogDeleted'), 'confirmation');
6871
}

main/exercise/pending.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,22 @@ function updateExerciseList(courseId) {
296296
]
297297
);
298298

299+
$userOptions = [];
300+
if (!empty($filter_user)) {
301+
$userInfo = api_get_user_info($filter_user);
302+
if (!empty($userInfo)) {
303+
$userOptions[$filter_user] = $userInfo['complete_name_with_username'];
304+
}
305+
}
306+
$form->addSelectAjax(
307+
'filter_by_user',
308+
get_lang('User'),
309+
$userOptions,
310+
[
311+
'url' => api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?a=get_user_like',
312+
]
313+
);
314+
299315
$status = [
300316
1 => get_lang('All'),
301317
2 => get_lang('Validated'),
@@ -445,8 +461,12 @@ function action_formatter(cellvalue, options, rowObject) {
445461
return "<span title=\""+tabLoginx[0]+rowObject[2]+tabLoginx[1]+"\">"+cellvalue+"</span>";
446462
}';
447463

448-
$extra_params['autowidth'] = 'true';
449-
$extra_params['height'] = 'auto';
464+
$extra_params = [
465+
'autowidth' => 'true',
466+
'height' => 'auto',
467+
'sortname' => 'exe_date',
468+
'sortorder' => 'asc',
469+
];
450470
$gridJs = Display::grid_js(
451471
'results',
452472
$url,

main/inc/ajax/document.ajax.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
use Chamilo\CoreBundle\Component\Editor\Driver\Driver;
9+
use Chamilo\CoreBundle\Component\Editor\Driver\PersonalDriver;
910

1011
require_once __DIR__.'/../global.inc.php';
1112

@@ -225,6 +226,22 @@
225226
exit;
226227
}
227228

229+
try {
230+
$fileUpload['size'] = DocumentManager::autoResizeImageIfNeeded(
231+
$fileUpload['size'],
232+
$fileUpload['tmp_name']
233+
);
234+
} catch (Exception $e) {
235+
echo json_encode([
236+
'uploaded' => 0,
237+
'error' => [
238+
'message' => $e->getMessage(),
239+
]
240+
]);
241+
242+
exit;
243+
}
244+
228245
$isAllowedToEdit = api_is_allowed_to_edit(null, true);
229246
if ($isAllowedToEdit) {
230247
$globalFile = ['files' => $fileUpload];

main/inc/lib/PortfolioController.php

Lines changed: 94 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Chamilo\UserBundle\Entity\User;
1717
use Doctrine\ORM\Query\Expr\Join;
1818
use Mpdf\MpdfException;
19+
use Symfony\Component\Filesystem\Exception\FileNotFoundException;
1920
use Symfony\Component\Filesystem\Filesystem;
2021
use Symfony\Component\HttpFoundation\Request as HttpRequest;
2122

@@ -1417,7 +1418,7 @@ public function view(Portfolio $item, $urlUser)
14171418
);
14181419

14191420
$urlUserString = "";
1420-
if (isset($urlUser)) {
1421+
if (!empty($urlUser)) {
14211422
$urlUserString = "user=".$urlUser;
14221423
}
14231424

@@ -2350,12 +2351,24 @@ public function exportZip(HttpRequest $httpRequest)
23502351
$itemDirectory = $item->getCreationDate()->format('Y-m-d-H-i-s');
23512352

23522353
$itemFilename = sprintf('%s/items/%s/item.html', $tempPortfolioDirectory, $itemDirectory);
2353-
$itemFileContent = $this->fixImagesSourcesToHtml($itemsHtml[$i]);
2354+
$imagePaths = [];
2355+
$itemFileContent = $this->fixMediaSourcesToHtml($itemsHtml[$i], $imagePaths);
23542356

23552357
$fs->dumpFile($itemFilename, $itemFileContent);
23562358

23572359
$filenames[] = $itemFilename;
23582360

2361+
foreach ($imagePaths as $imagePath) {
2362+
$inlineFile = dirname($itemFilename).'/'.basename($imagePath);
2363+
2364+
try {
2365+
$filenames[] = $inlineFile;
2366+
$fs->copy($imagePath, $inlineFile);
2367+
} catch (FileNotFoundException $notFoundException) {
2368+
continue;
2369+
}
2370+
}
2371+
23592372
$attachments = $attachmentsRepo->findFromItem($item);
23602373

23612374
/** @var PortfolioAttachment $attachment */
@@ -2367,12 +2380,15 @@ public function exportZip(HttpRequest $httpRequest)
23672380
$attachment->getFilename()
23682381
);
23692382

2370-
$fs->copy(
2371-
$attachmentsDirectory.$attachment->getPath(),
2372-
$attachmentFilename
2373-
);
2374-
2375-
$filenames[] = $attachmentFilename;
2383+
try {
2384+
$fs->copy(
2385+
$attachmentsDirectory.$attachment->getPath(),
2386+
$attachmentFilename
2387+
);
2388+
$filenames[] = $attachmentFilename;
2389+
} catch (FileNotFoundException $notFoundException) {
2390+
continue;
2391+
}
23762392
}
23772393

23782394
$tblItemsData[] = [
@@ -2397,13 +2413,25 @@ public function exportZip(HttpRequest $httpRequest)
23972413
foreach ($comments as $i => $comment) {
23982414
$commentDirectory = $comment->getDate()->format('Y-m-d-H-i-s');
23992415

2400-
$commentFileContent = $this->fixImagesSourcesToHtml($commentsHtml[$i]);
2416+
$imagePaths = [];
2417+
$commentFileContent = $this->fixMediaSourcesToHtml($commentsHtml[$i], $imagePaths);
24012418
$commentFilename = sprintf('%s/comments/%s/comment.html', $tempPortfolioDirectory, $commentDirectory);
24022419

24032420
$fs->dumpFile($commentFilename, $commentFileContent);
24042421

24052422
$filenames[] = $commentFilename;
24062423

2424+
foreach ($imagePaths as $imagePath) {
2425+
$inlineFile = dirname($commentFilename).'/'.basename($imagePath);
2426+
2427+
try {
2428+
$filenames[] = $inlineFile;
2429+
$fs->copy($imagePath, $inlineFile);
2430+
} catch (FileNotFoundException $notFoundException) {
2431+
continue;
2432+
}
2433+
}
2434+
24072435
$attachments = $attachmentsRepo->findFromComment($comment);
24082436

24092437
/** @var PortfolioAttachment $attachment */
@@ -2415,12 +2443,15 @@ public function exportZip(HttpRequest $httpRequest)
24152443
$attachment->getFilename()
24162444
);
24172445

2418-
$fs->copy(
2419-
$attachmentsDirectory.$attachment->getPath(),
2420-
$attachmentFilename
2421-
);
2422-
2423-
$filenames[] = $attachmentFilename;
2446+
try {
2447+
$fs->copy(
2448+
$attachmentsDirectory.$attachment->getPath(),
2449+
$attachmentFilename
2450+
);
2451+
$filenames[] = $attachmentFilename;
2452+
} catch (FileNotFoundException $notFoundException) {
2453+
continue;
2454+
}
24242455
}
24252456

24262457
$tblCommentsData[] = [
@@ -4277,44 +4308,73 @@ private function getCommentsInHtmlFormatted(array $comments): array
42774308
return $commentsHtml;
42784309
}
42794310

4280-
private function fixImagesSourcesToHtml(string $htmlContent): string
4311+
/**
4312+
* @param string $htmlContent
4313+
* @param array $imagePaths Relative paths found in $htmlContent
4314+
*
4315+
* @return string
4316+
*/
4317+
private function fixMediaSourcesToHtml(string $htmlContent, array &$imagePaths): string
42814318
{
42824319
$doc = new DOMDocument();
42834320
@$doc->loadHTML($htmlContent);
42844321

4285-
$elements = $doc->getElementsByTagName('img');
4322+
$tagsWithSrc = ['img', 'video', 'audio', 'source'];
4323+
/** @var array<int, \DOMElement> $elements */
4324+
$elements = [];
4325+
4326+
foreach ($tagsWithSrc as $tag) {
4327+
foreach ($doc->getElementsByTagName($tag) as $element) {
4328+
if ($element->hasAttribute('src')) {
4329+
$elements[] = $element;
4330+
}
4331+
}
4332+
}
42864333

4287-
if (empty($elements->length)) {
4334+
if (empty($elements)) {
42884335
return $htmlContent;
42894336
}
42904337

4291-
$webCoursePath = api_get_path(WEB_COURSE_PATH);
4292-
$webUploadPath = api_get_path(WEB_UPLOAD_PATH);
4338+
/** @var array<int, \DOMElement> $anchorElements */
4339+
$anchorElements = $doc->getElementsByTagName('a');
4340+
4341+
$webPath = api_get_path(WEB_PATH);
4342+
$sysPath = rtrim(api_get_path(SYS_PATH), '/');
4343+
4344+
$paths = [
4345+
'/app/upload/' => $sysPath,
4346+
'/courses/' => $sysPath.'/app'
4347+
];
42934348

4294-
/** @var \DOMElement $element */
42954349
foreach ($elements as $element) {
42964350
$src = trim($element->getAttribute('src'));
42974351

4298-
if (strpos($src, 'http') === 0) {
4352+
if (!str_starts_with($src, '/')
4353+
&& !str_starts_with($src, $webPath)
4354+
) {
42994355
continue;
43004356
}
43014357

4302-
if (strpos($src, '/app/upload/') === 0) {
4303-
$element->setAttribute(
4304-
'src',
4305-
preg_replace('/\/app/upload\//', $webUploadPath, $src, 1)
4306-
);
4358+
// to search anchors linking to files
4359+
if ($anchorElements->length > 0) {
4360+
foreach ($anchorElements as $anchorElement) {
4361+
if (!$anchorElement->hasAttribute('href')) {
4362+
continue;
4363+
}
43074364

4308-
continue;
4365+
if ($src === $anchorElement->getAttribute('href')) {
4366+
$anchorElement->setAttribute('href', basename($src));
4367+
}
4368+
}
43094369
}
43104370

4311-
if (strpos($src, '/courses/') === 0) {
4312-
$element->setAttribute(
4313-
'src',
4314-
preg_replace('/\/courses\//', $webCoursePath, $src, 1)
4315-
);
4371+
$src = str_replace($webPath, '/', $src);
43164372

4317-
continue;
4373+
foreach ($paths as $prefix => $basePath) {
4374+
if (str_starts_with($src, $prefix)) {
4375+
$imagePaths[] = $basePath.urldecode($src);
4376+
$element->setAttribute('src', basename($src));
4377+
}
43184378
}
43194379
}
43204380

0 commit comments

Comments
 (0)