Optimisation de l'export
This commit is contained in:
parent
9c5f6448b1
commit
485392e772
@ -1749,7 +1749,7 @@ class course extends common
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Soumission du formulaire
|
// Soumission du formulaire
|
||||||
if ($this->isPost()) {
|
if ($this->isPost()) {
|
||||||
$datas = '';
|
$datas = '';
|
||||||
@ -1759,21 +1759,25 @@ class course extends common
|
|||||||
if ($this->getInput('courseManageExport' . $pageId, helper::FILTER_BOOLEAN) === true) {
|
if ($this->getInput('courseManageExport' . $pageId, helper::FILTER_BOOLEAN) === true) {
|
||||||
$pageContent = $this->getPage($pageId, $courseId);
|
$pageContent = $this->getPage($pageId, $courseId);
|
||||||
|
|
||||||
// Extraction des URLs des ressources (images, fichiers, etc.)
|
// Extraction des URLs des ressources (images, vidéos, fichiers, etc.)
|
||||||
preg_match_all('/<img[^>]+src=["\'](.*?)["\']/i', $pageContent, $imgMatches);
|
preg_match_all('/<img[^>]+src=["\'](.*?)["\']/i', $pageContent, $imgMatches); // Images
|
||||||
preg_match_all('/<a[^>]+href=["\'](.*?)["\']/i', $pageContent, $linkMatches);
|
preg_match_all('/<a[^>]+href=["\'](.*?)["\']/i', $pageContent, $linkMatches); // Liens
|
||||||
|
preg_match_all('/<video[^>]+src=["\'](.*?)["\']/i', $pageContent, $videoMatches); // Vidéos directes
|
||||||
|
preg_match_all('/<source[^>]+src=["\'](.*?)["\']/i', $pageContent, $sourceMatches); // Vidéos dans balises <source>
|
||||||
|
|
||||||
if (!empty($imgMatches[1])) {
|
// Traitement des images
|
||||||
$resources = array_merge($resources, $imgMatches[1]);
|
$this->processResources($pageContent, '/<img[^>]+src=["\'](.*?)["\']/i', $resources);
|
||||||
|
|
||||||
// Remplacement des chemins pour les images dans $pageContent
|
// Traitement des vidéos directes via <video>
|
||||||
foreach ($imgMatches[1] as $resourceUrl) {
|
$this->processResources($pageContent, '/<video[^>]+src=["\'](.*?)["\']/i', $resources);
|
||||||
$resourcePath = parse_url($resourceUrl, PHP_URL_PATH);
|
|
||||||
$resourceFile = basename($resourcePath);
|
|
||||||
$pageContent = str_replace($resourceUrl, $resourceFile, $pageContent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Traitement des sources dans les balises <source> (utilisées dans <video> ou <audio>)
|
||||||
|
$this->processResources($pageContent, '/<source[^>]+src=["\'](.*?)["\']/i', $resources);
|
||||||
|
|
||||||
|
// Traitement des liens <a>
|
||||||
|
$this->processResources($pageContent, '/<a[^>]+href=["\'](.*?)["\']/i', $resources);
|
||||||
|
|
||||||
|
// Traitement des liens
|
||||||
if (!empty($linkMatches[1])) {
|
if (!empty($linkMatches[1])) {
|
||||||
$resources = array_merge($resources, $linkMatches[1]);
|
$resources = array_merge($resources, $linkMatches[1]);
|
||||||
|
|
||||||
@ -1806,14 +1810,14 @@ class course extends common
|
|||||||
|
|
||||||
// Ajouter les balises HTML manquantes
|
// Ajouter les balises HTML manquantes
|
||||||
$datas = '<!DOCTYPE html>
|
$datas = '<!DOCTYPE html>
|
||||||
<html lang="fr">
|
<html lang="fr">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>' . $this->getData(['course', $courseId, 'title']). '</title>
|
<title>' . $this->getData(['course', $courseId, 'title']) . '</title>
|
||||||
<link rel="stylesheet" href="style.css">
|
<link rel="stylesheet" href="style.css">
|
||||||
</head>
|
</head>
|
||||||
<body>' . $datas . '</body></html>';
|
<body>' . $datas . '</body></html>';
|
||||||
|
|
||||||
// Sauvegarder le fichier HTML
|
// Sauvegarder le fichier HTML
|
||||||
file_put_contents($path . '/export/' . $courseId . '_export.html', $datas, LOCK_EX);
|
file_put_contents($path . '/export/' . $courseId . '_export.html', $datas, LOCK_EX);
|
||||||
@ -1830,10 +1834,6 @@ class course extends common
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Valeurs en sortie
|
// Valeurs en sortie
|
||||||
$this->addOutput([
|
$this->addOutput([
|
||||||
'title' => helper::translate('Exporter les pages'),
|
'title' => helper::translate('Exporter les pages'),
|
||||||
@ -1842,6 +1842,22 @@ class course extends common
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function processResources(&$pageContent, $regex, &$resources)
|
||||||
|
{
|
||||||
|
preg_match_all($regex, $pageContent, $matches);
|
||||||
|
|
||||||
|
if (!empty($matches[1])) {
|
||||||
|
$resources = array_merge($resources, $matches[1]);
|
||||||
|
|
||||||
|
// Remplacement des chemins dans $pageContent
|
||||||
|
foreach ($matches[1] as $resourceUrl) {
|
||||||
|
$resourcePath = parse_url($resourceUrl, PHP_URL_PATH);
|
||||||
|
$resourceFile = basename($resourcePath);
|
||||||
|
$pageContent = str_replace($resourceUrl, $resourceFile, $pageContent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sauvegarde d'un cours sans option
|
* Sauvegarde d'un cours sans option
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user