-
-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Backport release_3_9] Js files finder (#5051)
* UserFileFinder class * update controller to use UserFileFinder class * add 'param' methode parameter for AppContext Interface and JelixContext * ContextForText simply return url * unit tests, add js files in default/repo/subfolder --------- Co-authored-by: Raphaël Martin <[email protected]>
- Loading branch information
Showing
18 changed files
with
1,369 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
/** | ||
* @author 3Liz | ||
* @copyright 2024 3liz.com | ||
* | ||
* @see 3liz.com | ||
* | ||
* @license MIT | ||
*/ | ||
|
||
namespace Lizmap\Project; | ||
|
||
class ProjectFilesFinder | ||
{ | ||
public function listFileURLS(Project $project, $ignoreRepoAllowUserDefined = false) | ||
{ | ||
$jsUrls = array(); | ||
$mjsUrls = array(); | ||
$cssUrls = array(); | ||
if ($ignoreRepoAllowUserDefined || $project->getRepository()->allowUserDefinedThemes()) { | ||
$appContext = $project->getAppContext(); | ||
$jsDirArray = array('default', $project->getKey()); | ||
$repositoryPath = $project->getRepository()->getPath(); | ||
foreach ($jsDirArray as $dir) { | ||
$items = array( | ||
// current repository | ||
'media/js/', | ||
// or root (js shared over repositories) | ||
'../media/js/', | ||
); | ||
foreach ($items as $item) { | ||
$jsPathRoot = realpath($repositoryPath.$item.$dir); | ||
if (!is_dir($jsPathRoot)) { | ||
continue; | ||
} | ||
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($jsPathRoot)) as $filename) { | ||
$fileExtension = pathinfo($filename, PATHINFO_EXTENSION); | ||
if ($fileExtension == 'js' || $fileExtension == 'mjs' || $fileExtension == 'css') { | ||
$jsPath = realpath($filename); | ||
$jsRelPath = $item.$dir.str_replace($jsPathRoot, '', $jsPath); | ||
$url = 'view~media:getMedia'; | ||
if ($fileExtension == 'css') { | ||
$url = 'view~media:getCssFile'; | ||
} | ||
|
||
$fileUrl = $appContext->getUrl( | ||
$url, | ||
array( | ||
'repository' => $project->getRepositoryKey(), | ||
'project' => $project->getKey(), | ||
'mtime' => filemtime($filename), | ||
'path' => $jsRelPath, | ||
) | ||
); | ||
if ($fileExtension == 'js') { | ||
$jsUrls[] = $fileUrl; | ||
} elseif ($fileExtension == 'mjs') { | ||
$mjsUrls[] = $fileUrl; | ||
} else { | ||
$cssUrls[] = $fileUrl; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
return array('css' => $cssUrls, 'js' => $jsUrls, 'mjs' => $mjsUrls); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
Empty file.
Oops, something went wrong.