@@ -2350,12 +2350,20 @@ public function exportZip(HttpRequest $httpRequest)
2350
2350
$ itemDirectory = $ item ->getCreationDate ()->format ('Y-m-d-H-i-s ' );
2351
2351
2352
2352
$ itemFilename = sprintf ('%s/items/%s/item.html ' , $ tempPortfolioDirectory , $ itemDirectory );
2353
- $ itemFileContent = $ this ->fixImagesSourcesToHtml ($ itemsHtml [$ i ]);
2353
+ $ imagePaths = [];
2354
+ $ itemFileContent = $ this ->fixImagesSourcesToHtml ($ itemsHtml [$ i ], $ imagePaths );
2354
2355
2355
2356
$ fs ->dumpFile ($ itemFilename , $ itemFileContent );
2356
2357
2357
2358
$ filenames [] = $ itemFilename ;
2358
2359
2360
+ foreach ($ imagePaths as $ imagePath ) {
2361
+ $ inlineFile = dirname ($ itemFilename ).'/ ' .basename ($ imagePath );
2362
+ $ filenames [] = $ inlineFile ;
2363
+ $ fs ->copy ($ imagePath , $ inlineFile );
2364
+ }
2365
+
2366
+
2359
2367
$ attachments = $ attachmentsRepo ->findFromItem ($ item );
2360
2368
2361
2369
/** @var PortfolioAttachment $attachment */
@@ -2397,13 +2405,20 @@ public function exportZip(HttpRequest $httpRequest)
2397
2405
foreach ($ comments as $ i => $ comment ) {
2398
2406
$ commentDirectory = $ comment ->getDate ()->format ('Y-m-d-H-i-s ' );
2399
2407
2400
- $ commentFileContent = $ this ->fixImagesSourcesToHtml ($ commentsHtml [$ i ]);
2408
+ $ imagePaths = [];
2409
+ $ commentFileContent = $ this ->fixImagesSourcesToHtml ($ commentsHtml [$ i ], $ imagePaths );
2401
2410
$ commentFilename = sprintf ('%s/comments/%s/comment.html ' , $ tempPortfolioDirectory , $ commentDirectory );
2402
2411
2403
2412
$ fs ->dumpFile ($ commentFilename , $ commentFileContent );
2404
2413
2405
2414
$ filenames [] = $ commentFilename ;
2406
2415
2416
+ foreach ($ imagePaths as $ imagePath ) {
2417
+ $ inlineFile = dirname ($ commentFilename ).'/ ' .basename ($ imagePath );
2418
+ $ filenames [] = $ inlineFile ;
2419
+ $ fs ->copy ($ imagePath , $ inlineFile );
2420
+ }
2421
+
2407
2422
$ attachments = $ attachmentsRepo ->findFromComment ($ comment );
2408
2423
2409
2424
/** @var PortfolioAttachment $attachment */
@@ -4277,7 +4292,7 @@ private function getCommentsInHtmlFormatted(array $comments): array
4277
4292
return $ commentsHtml ;
4278
4293
}
4279
4294
4280
- private function fixImagesSourcesToHtml (string $ htmlContent ): string
4295
+ private function fixImagesSourcesToHtml (string $ htmlContent, array & $ imagePaths ): string
4281
4296
{
4282
4297
$ doc = new DOMDocument ();
4283
4298
@$ doc ->loadHTML ($ htmlContent );
@@ -4288,30 +4303,38 @@ private function fixImagesSourcesToHtml(string $htmlContent): string
4288
4303
return $ htmlContent ;
4289
4304
}
4290
4305
4291
- $ webCoursePath = api_get_path (WEB_COURSE_PATH );
4292
- $ webUploadPath = api_get_path (WEB_UPLOAD_PATH );
4306
+ $ webPath = api_get_path (WEB_PATH );
4307
+ $ sysPath = rtrim ( api_get_path (SYS_PATH ), ' / ' );
4293
4308
4294
4309
/** @var \DOMElement $element */
4295
4310
foreach ($ elements as $ element ) {
4296
4311
$ src = trim ($ element ->getAttribute ('src ' ));
4297
4312
4298
- if (strpos ($ src , 'http ' ) === 0 ) {
4313
+ if (!str_starts_with ($ src , '/ ' )
4314
+ && !str_starts_with ($ src , $ webPath )
4315
+ ) {
4299
4316
continue ;
4300
4317
}
4301
4318
4319
+ $ src = str_replace ($ webPath , '/ ' , $ src );
4320
+
4302
4321
if (strpos ($ src , '/app/upload/ ' ) === 0 ) {
4322
+ $ imagePaths [] = $ sysPath .$ src ;
4323
+
4303
4324
$ element ->setAttribute (
4304
4325
'src ' ,
4305
- preg_replace ( ' /\/app/upload\// ' , $ webUploadPath , $ src, 1 )
4326
+ basename ( $ src )
4306
4327
);
4307
4328
4308
4329
continue ;
4309
4330
}
4310
4331
4311
4332
if (strpos ($ src , '/courses/ ' ) === 0 ) {
4333
+ $ imagePaths [] = $ sysPath .'/app ' .$ src ;
4334
+
4312
4335
$ element ->setAttribute (
4313
4336
'src ' ,
4314
- preg_replace ( ' /\/courses\// ' , $ webCoursePath , $ src, 1 )
4337
+ basename ( $ src )
4315
4338
);
4316
4339
4317
4340
continue ;
0 commit comments