diff options
| author | polo <ordipolo@gmx.fr> | 2026-07-26 19:29:53 +0200 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2026-07-26 19:29:53 +0200 |
| commit | 58514668410cb902dab613221a8e7f963cc36317 (patch) | |
| tree | 98d0ec77ba9689997e4af395679ce061b2bff3f9 /view | |
| parent | fea733a16a666e9b7ecf4729b126d65d1ad9208d (diff) | |
| download | melaine-58514668410cb902dab613221a8e7f963cc36317.tar.gz melaine-58514668410cb902dab613221a8e7f963cc36317.tar.bz2 melaine-58514668410cb902dab613221a8e7f963cc36317.zip | |
versioning fichiers CSS et JS
Diffstat (limited to 'view')
| -rw-r--r-- | view/Versioning.php | 24 | ||||
| -rw-r--r-- | view/accueil.php | 4 | ||||
| -rw-r--r-- | view/album.php | 23 | ||||
| -rw-r--r-- | view/backup.php | 6 | ||||
| -rw-r--r-- | view/discographie.php | 24 | ||||
| -rw-r--r-- | view/pageArticlesSimples.php | 32 | ||||
| -rw-r--r-- | view/password.php | 6 | ||||
| -rw-r--r-- | view/template.php | 4 |
8 files changed, 51 insertions, 72 deletions
diff --git a/view/Versioning.php b/view/Versioning.php new file mode 100644 index 0000000..f75afe1 --- /dev/null +++ b/view/Versioning.php | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | <?php | ||
| 2 | // view/Versioning.php | ||
| 3 | |||
| 4 | class Versioning { | ||
| 5 | static function insertCSS(string $name): string | ||
| 6 | { | ||
| 7 | return '<link rel="stylesheet" href="' . self::versionedFileURL('css', $name) . '">' . "\n"; | ||
| 8 | } | ||
| 9 | static function insertJS(string $name, bool $module = false): string | ||
| 10 | { | ||
| 11 | return '<script ' . ($module ? 'type="module"' : '') . ' src="' . self::versionedFileURL('js', $name) . '"></script>' . "\n"; | ||
| 12 | } | ||
| 13 | |||
| 14 | static function versionedFileURL(string $type, string $filename, ?string $custom_path = null): string | ||
| 15 | { | ||
| 16 | $path = $custom_path ?? 'public/' . $type . '/' . $filename . '.' . $type; // si custom_path, $type et $filename ne servent à rien | ||
| 17 | |||
| 18 | if(file_exists(getcwd() . '/' . $path)){ | ||
| 19 | $version = substr(md5_file($path), 0, 8); | ||
| 20 | return $path . '?v=' . $version; | ||
| 21 | } | ||
| 22 | return $path; // sécurité fichier absent | ||
| 23 | } | ||
| 24 | } | ||
diff --git a/view/accueil.php b/view/accueil.php index 1e8db56..d7297e4 100644 --- a/view/accueil.php +++ b/view/accueil.php | |||
| @@ -2,12 +2,12 @@ | |||
| 2 | // view/accueil.php | 2 | // view/accueil.php |
| 3 | 3 | ||
| 4 | // variable $js | 4 | // variable $js |
| 5 | $js = Versioning::insertJS('main'); | ||
| 5 | ob_start(); | 6 | ob_start(); |
| 6 | ?> | 7 | ?> |
| 7 | <script src="public/main.js" ></script> | ||
| 8 | <script>versMenu();</script> | 8 | <script>versMenu();</script> |
| 9 | <?php | 9 | <?php |
| 10 | $js = ob_get_clean(); | 10 | $js .= ob_get_clean(); |
| 11 | 11 | ||
| 12 | // variable $header | 12 | // variable $header |
| 13 | ob_start(); | 13 | ob_start(); |
diff --git a/view/album.php b/view/album.php index 6fcca36..e568aa2 100644 --- a/view/album.php +++ b/view/album.php | |||
| @@ -2,29 +2,18 @@ | |||
| 2 | // view/album.php | 2 | // view/album.php |
| 3 | 3 | ||
| 4 | // variable $css | 4 | // variable $css |
| 5 | // utilise discographie.css | 5 | $css = Versioning::insertCSS('discographie'); |
| 6 | ob_start(); | 6 | $css .= Versioning::insertCSS('donnees_hors_editeur'); |
| 7 | ?> | ||
| 8 | <link rel="stylesheet" type="text/css" href="public/css/discographie.css"> | ||
| 9 | <link rel="stylesheet" type="text/css" href="public/css/donnees_hors_editeur.css"> | ||
| 10 | <?php | ||
| 11 | $css = ob_get_clean(); | ||
| 12 | 7 | ||
| 13 | // variable $js | 8 | // variable $js |
| 14 | ob_start(); | 9 | $js = Versioning::insertJS('main'); |
| 15 | ?> | 10 | //$js .= Versioning::insertJS('file_upload'); |
| 16 | <script src="public/main.js" ></script> | 11 | |
| 17 | <!-- <script type="text/javascript" src="public/file_upload.js" ></script> --> | ||
| 18 | <?php | ||
| 19 | if(isset($_GET['action']) && $_GET['action'] === 'edition') | 12 | if(isset($_GET['action']) && $_GET['action'] === 'edition') |
| 20 | { | 13 | { |
| 21 | |||
| 22 | // bibliothèques JS ckeditor | 14 | // bibliothèques JS ckeditor |
| 23 | ?> | 15 | $js .= '<script src="' . Versioning::versionedFileURL('', '', 'lib/ckeditor5/build/ckeditor.js') . '"></script>'; |
| 24 | <script src="lib/ckeditor5/build/ckeditor.js"></script> | ||
| 25 | <?php | ||
| 26 | } | 16 | } |
| 27 | $js = ob_get_clean(); | ||
| 28 | 17 | ||
| 29 | // variable $header | 18 | // variable $header |
| 30 | ob_start(); | 19 | ob_start(); |
diff --git a/view/backup.php b/view/backup.php index 78e2d04..c56661f 100644 --- a/view/backup.php +++ b/view/backup.php | |||
| @@ -77,12 +77,12 @@ elseif(isset($_GET['action']) && $_GET['action'] == 'restauration') | |||
| 77 | <title><?= $title ?></title> | 77 | <title><?= $title ?></title> |
| 78 | <!-- <link rel="shortcut icon" type="image/x-icon" href="favicon.ico" /> --> | 78 | <!-- <link rel="shortcut icon" type="image/x-icon" href="favicon.ico" /> --> |
| 79 | <link rel="icon" type="image/png" href="public/mouette-logo.png"> | 79 | <link rel="icon" type="image/png" href="public/mouette-logo.png"> |
| 80 | <link rel="stylesheet" type="text/css" href="public/css/normalize.css"> | 80 | <?= Versioning::insertCSS('normalize') ?> |
| 81 | <link rel="stylesheet" type="text/css" href="public/css/main.css"> | 81 | <?= Versioning::insertCSS('main') ?> |
| 82 | <?php | 82 | <?php |
| 83 | if(isset($_GET['action']) && $_GET['action'] == 'restauration') | 83 | if(isset($_GET['action']) && $_GET['action'] == 'restauration') |
| 84 | { | 84 | { |
| 85 | echo('<script src="public/file_upload.js" ></script>'); | 85 | echo Versioning::insertJS('file_upload'); |
| 86 | } | 86 | } |
| 87 | ?> | 87 | ?> |
| 88 | <meta name="viewport" content="width=device-width, initial-scale=1.0"> | 88 | <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
diff --git a/view/discographie.php b/view/discographie.php index 84358db..96026bf 100644 --- a/view/discographie.php +++ b/view/discographie.php | |||
| @@ -2,30 +2,18 @@ | |||
| 2 | // view/discographie.php | 2 | // view/discographie.php |
| 3 | 3 | ||
| 4 | // variable $css | 4 | // variable $css |
| 5 | ob_start(); | 5 | $css = Versioning::insertCSS($page); |
| 6 | ?> | 6 | $css .= Versioning::insertCSS('donnees_hors_editeur'); |
| 7 | <link rel="stylesheet" type="text/css" href="public/css/<?= $page ?>.css"> | ||
| 8 | <link rel="stylesheet" type="text/css" href="public/css/donnees_hors_editeur.css"> | ||
| 9 | <?php | ||
| 10 | $css = ob_get_clean(); | ||
| 11 | |||
| 12 | 7 | ||
| 13 | // variable $js | 8 | // variable $js |
| 14 | ob_start(); | 9 | $js = Versioning::insertJS('main'); |
| 15 | ?> | 10 | //$js .= Versioning::insertJS('file_upload'); |
| 16 | <script src="public/main.js"></script> | 11 | |
| 17 | <!-- <script type="text/javascript" src="public/file_upload.js" ></script> --> | ||
| 18 | <?php | ||
| 19 | if(isset($_GET['action']) && $_GET['action'] === 'edition') | 12 | if(isset($_GET['action']) && $_GET['action'] === 'edition') |
| 20 | { | 13 | { |
| 21 | |||
| 22 | // bibliothèques JS ckeditor | 14 | // bibliothèques JS ckeditor |
| 23 | ?> | 15 | $js .= '<script src="' . Versioning::versionedFileURL('', '', 'lib/ckeditor5/build/ckeditor.js') . '"></script>'; |
| 24 | <script src="lib/ckeditor5/build/ckeditor.js"></script> | ||
| 25 | <?php | ||
| 26 | } | 16 | } |
| 27 | $js = ob_get_clean(); | ||
| 28 | |||
| 29 | 17 | ||
| 30 | // variable $header | 18 | // variable $header |
| 31 | ob_start(); | 19 | ob_start(); |
diff --git a/view/pageArticlesSimples.php b/view/pageArticlesSimples.php index d282964..fcb453a 100644 --- a/view/pageArticlesSimples.php +++ b/view/pageArticlesSimples.php | |||
| @@ -2,39 +2,17 @@ | |||
| 2 | // view/pageArticleSimple.php | 2 | // view/pageArticleSimple.php |
| 3 | 3 | ||
| 4 | // variable $css | 4 | // variable $css |
| 5 | ob_start(); | 5 | $css = $page === 'menu' ? Versioning::insertCSS('menu') : Versioning::insertCSS('pages_articles_simples'); |
| 6 | if($page == 'menu') | 6 | $css .= Versioning::insertCSS('donnees_hors_editeur'); |
| 7 | { | ||
| 8 | ?> | ||
| 9 | <link rel="stylesheet" type="text/css" href="public/css/menu.css"> | ||
| 10 | <?php | ||
| 11 | } | ||
| 12 | else | ||
| 13 | { | ||
| 14 | ?> | ||
| 15 | <link rel="stylesheet" type="text/css" href="public/css/pages_articles_simples.css"> | ||
| 16 | <?php | ||
| 17 | } | ||
| 18 | ?> | ||
| 19 | <link rel="stylesheet" type="text/css" href="public/css/donnees_hors_editeur.css"> | ||
| 20 | <?php | ||
| 21 | $css = ob_get_clean(); | ||
| 22 | 7 | ||
| 23 | //variable $js | 8 | //variable $js |
| 24 | ob_start(); | 9 | $js = Versioning::insertJS('main'); |
| 25 | ?> | 10 | |
| 26 | <script src="public/main.js"></script> | ||
| 27 | <?php | ||
| 28 | if(isset($_GET['action']) && $_GET['action'] == 'editor') | 11 | if(isset($_GET['action']) && $_GET['action'] == 'editor') |
| 29 | { | 12 | { |
| 30 | |||
| 31 | // bibliothèques JS ckeditor | 13 | // bibliothèques JS ckeditor |
| 32 | ?> | 14 | $js .= '<script src="' . Versioning::versionedFileURL('', '', 'lib/ckeditor5/build/ckeditor.js') . '"></script>'; |
| 33 | <script src="lib/ckeditor5/build/ckeditor.js"></script> | ||
| 34 | <?php | ||
| 35 | } | 15 | } |
| 36 | $js = ob_get_clean(); | ||
| 37 | |||
| 38 | 16 | ||
| 39 | // message lecteur multimedia | 17 | // message lecteur multimedia |
| 40 | if($page == 'archives') | 18 | if($page == 'archives') |
diff --git a/view/password.php b/view/password.php index ae153b5..62f53ec 100644 --- a/view/password.php +++ b/view/password.php | |||
| @@ -75,9 +75,9 @@ ob_start(); | |||
| 75 | 75 | ||
| 76 | <!-- <link rel="shortcut icon" type="image/x-icon" href="favicon.ico" /> --> | 76 | <!-- <link rel="shortcut icon" type="image/x-icon" href="favicon.ico" /> --> |
| 77 | <link rel="icon" type="image/png" href="public/mouette-logo.png"> | 77 | <link rel="icon" type="image/png" href="public/mouette-logo.png"> |
| 78 | <link rel="stylesheet" type="text/css" href="public/css/normalize.css"> | 78 | <?= Versioning::insertCSS('normalize') ?> |
| 79 | <link rel="stylesheet" type="text/css" href="public/css/main.css"> | 79 | <?= Versioning::insertCSS('main') ?> |
| 80 | <script src="public/main.js" ></script> | 80 | <?= Versioning::insertJS('main') ?> |
| 81 | <meta name="viewport" content="width=device-width, initial-scale=1.0"> | 81 | <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 82 | </head> | 82 | </head> |
| 83 | 83 | ||
diff --git a/view/template.php b/view/template.php index dfe68bd..3facc13 100644 --- a/view/template.php +++ b/view/template.php | |||
| @@ -10,9 +10,9 @@ | |||
| 10 | 10 | ||
| 11 | <!-- <link rel="shortcut icon" type="image/x-icon" href="public/favicon.ico" /> --> | 11 | <!-- <link rel="shortcut icon" type="image/x-icon" href="public/favicon.ico" /> --> |
| 12 | <link rel="icon" type="image/png" href="public/mouette-logo.png"> | 12 | <link rel="icon" type="image/png" href="public/mouette-logo.png"> |
| 13 | <link rel="stylesheet" type="text/css" href="public/css/normalize.css"> | ||
| 14 | <link rel="stylesheet" type="text/css" href="public/css/main.css"> | ||
| 15 | <?php | 13 | <?php |
| 14 | echo Versioning::insertCSS('normalize'); | ||
| 15 | echo Versioning::insertCSS('main'); | ||
| 16 | if(isset($css)) // fichiers CSS supplémentaires | 16 | if(isset($css)) // fichiers CSS supplémentaires |
| 17 | { | 17 | { |
| 18 | echo($css); | 18 | echo($css); |
