lumo:creation_plugin_dokuwiki_namespacelogo:accueil
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| lumo:creation_plugin_dokuwiki_namespacelogo:accueil [2026/03/16 17:13] – estro | lumo:creation_plugin_dokuwiki_namespacelogo:accueil [2026/03/19 07:20] (Version actuelle) – estro | ||
|---|---|---|---|
| Ligne 2: | Ligne 2: | ||
| ---- | ---- | ||
| [[../ | [[../ | ||
| + | <adm danger Créer les fichiers> | ||
| + | Création d'un dossier pour y créer les fichiers de définition du " | ||
| + | <code bash> | ||
| + | cd / | ||
| + | mkdir namespacelogo | ||
| + | cd namespacelogo | ||
| + | touch plugin.info.txt action.php helper.php style.less | ||
| + | chmod 644 *.php *.less | ||
| + | chmod 755 ../ | ||
| + | </ | ||
| + | </ | ||
| <adm note plugin.info.txt> | <adm note plugin.info.txt> | ||
| < | < | ||
| Ligne 10: | Ligne 20: | ||
| date | date | ||
| name | name | ||
| - | desc | + | desc |
| </ | </ | ||
| </ | </ | ||
| + | <adm tip action.php > | ||
| + | <code php> | ||
| + | <?php | ||
| + | /** | ||
| + | * @license | ||
| + | * @author | ||
| + | | ||
| + | * Plugin DokuWiki pour afficher un logo par namespace | ||
| + | * Fonctionnalités : | ||
| + | * - Support de multiples formats (png, jpg, jpeg, gif, svg) | ||
| + | * - Fallback hiérarchique (cherche dans les namespaces parents) | ||
| + | * - Fallback vers le logo global si aucun logo trouvé | ||
| + | */ | ||
| + | |||
| + | class action_plugin_namespacelogo extends DokuWiki_Action_Plugin { | ||
| + | |||
| + | /** | ||
| + | * Formats d' | ||
| + | */ | ||
| + | protected $supportedFormats = [' | ||
| + | |||
| + | /** | ||
| + | * Enregistrer les hooks | ||
| + | */ | ||
| + | public function register(Doku_Event_Handler $controller) { | ||
| + | // Intercepter le rendu de l' | ||
| + | $controller-> | ||
| + | } | ||
| + | |||
| + | /** | ||
| + | * Injecter le logo du namespace dans l' | ||
| + | */ | ||
| + | public function _injectNamespaceLogo(Doku_Event $event, $param) { | ||
| + | global $ID; | ||
| + | | ||
| + | // Récupérer le namespace actuel | ||
| + | $ns = getNS($ID); | ||
| + | | ||
| + | // Trouver le chemin du logo (avec fallback hiérarchique) | ||
| + | $logoPath = $this-> | ||
| + | | ||
| + | if ($logoPath) { | ||
| + | // Générer l'URL de l' | ||
| + | $imgUrl = ml($logoPath); | ||
| + | | ||
| + | // Créer le HTML du logo | ||
| + | $logoHtml = '< | ||
| + | '< | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | '</ | ||
| + | | ||
| + | // Ajouter à la variable globale que le template pourra utiliser | ||
| + | $GLOBALS[' | ||
| + | } | ||
| + | } | ||
| + | |||
| + | /** | ||
| + | * Trouver le chemin du logo avec fallback hiérarchique | ||
| + | * @param string $ns Namespace de départ | ||
| + | * @return string|null Chemin du logo ou null si aucun trouvé | ||
| + | */ | ||
| + | protected function _findLogoPath($ns) { | ||
| + | // Liste des namespaces à vérifier (du plus spécifique au plus général) | ||
| + | $namespacesToCheck = $this-> | ||
| + | | ||
| + | // Vérifier chaque namespace dans l' | ||
| + | foreach ($namespacesToCheck as $checkNs) { | ||
| + | foreach ($this-> | ||
| + | $path = ':' | ||
| + | | ||
| + | if (@media_exists($path)) { | ||
| + | return $path; | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | | ||
| + | return null; | ||
| + | } | ||
| + | |||
| + | /** | ||
| + | * Construire la hiérarchie des namespaces pour le fallback | ||
| + | * Ex: ' | ||
| + | * @param string $ns Namespace de départ | ||
| + | * @return array Liste des namespaces à vérifier | ||
| + | */ | ||
| + | protected function _buildNamespaceHierarchy($ns) { | ||
| + | $hierarchy = []; | ||
| + | | ||
| + | // Ajouter le namespace actuel | ||
| + | if (!empty($ns)) { | ||
| + | $hierarchy[] = $ns; | ||
| + | } | ||
| + | | ||
| + | // Remonter dans la hiérarchie | ||
| + | $parts = explode(':', | ||
| + | while (count($parts) > 1) { | ||
| + | array_pop($parts); | ||
| + | $parentNs = implode(':', | ||
| + | if (!empty($parentNs)) { | ||
| + | $hierarchy[] = $parentNs; | ||
| + | } | ||
| + | } | ||
| + | | ||
| + | // Ajouter la racine (vide) pour le fallback global | ||
| + | $hierarchy[] = ''; | ||
| + | | ||
| + | return $hierarchy; | ||
| + | } | ||
| + | |||
| + | /** | ||
| + | * Extraire le namespace du chemin du logo pour l' | ||
| + | * @param string $path Chemin du logo (ex: ': | ||
| + | * @return string Nom du namespace | ||
| + | */ | ||
| + | protected function _extractNamespaceFromPath($path) { | ||
| + | // Supprimer les deux-points initiaux et le nom du fichier | ||
| + | $cleanPath = trim($path, ':' | ||
| + | $parts = explode(':', | ||
| + | | ||
| + | // Retirer le dernier élément (logo.png, etc.) | ||
| + | array_pop($parts); | ||
| + | | ||
| + | return implode(' | ||
| + | } | ||
| + | } | ||
| + | ?> | ||
| + | </ | ||
| + | </ | ||
| + | <adm example helper.php> | ||
| + | <code php> | ||
| + | <?php | ||
| + | /** | ||
| + | * @license | ||
| + | * @author | ||
| + | */ | ||
| + | |||
| + | class helper_plugin_namespacelogo extends DokuWiki_Plugin { | ||
| + | |||
| + | protected $supportedFormats = [' | ||
| + | |||
| + | /** | ||
| + | * Obtenir le logo du namespace actuel (avec fallback hiérarchique) | ||
| + | * @return string|null HTML du logo ou null si aucun logo trouvé | ||
| + | */ | ||
| + | public function getNamespaceLogo() { | ||
| + | global $ID; | ||
| + | | ||
| + | $ns = getNS($ID); | ||
| + | $logoPath = $this-> | ||
| + | | ||
| + | if ($logoPath) { | ||
| + | $imgUrl = ml($logoPath); | ||
| + | $nsName = $this-> | ||
| + | return '< | ||
| + | } | ||
| + | | ||
| + | return null; | ||
| + | } | ||
| + | |||
| + | /** | ||
| + | * Vérifier si un logo existe pour un namespace donné | ||
| + | * @param string $ns Namespace à vérifier | ||
| + | * @return bool | ||
| + | */ | ||
| + | public function hasLogo($ns) { | ||
| + | return $this-> | ||
| + | } | ||
| + | |||
| + | /** | ||
| + | * Obtenir le chemin du logo pour un namespace spécifique | ||
| + | * @param string $ns Namespace | ||
| + | * @return string|null | ||
| + | */ | ||
| + | public function getLogoPath($ns) { | ||
| + | return $this-> | ||
| + | } | ||
| + | |||
| + | /** | ||
| + | * Trouver le chemin du logo avec fallback hiérarchique | ||
| + | * @param string $ns Namespace de départ | ||
| + | * @return string|null | ||
| + | */ | ||
| + | protected function _findLogoPath($ns) { | ||
| + | $hierarchy = $this-> | ||
| + | | ||
| + | foreach ($hierarchy as $checkNs) { | ||
| + | foreach ($this-> | ||
| + | $path = ':' | ||
| + | | ||
| + | if (@media_exists($path)) { | ||
| + | return $path; | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | | ||
| + | return null; | ||
| + | } | ||
| + | |||
| + | /** | ||
| + | * Construire la hiérarchie des namespaces | ||
| + | * @param string $ns | ||
| + | * @return array | ||
| + | */ | ||
| + | protected function _buildNamespaceHierarchy($ns) { | ||
| + | $hierarchy = []; | ||
| + | | ||
| + | if (!empty($ns)) { | ||
| + | $hierarchy[] = $ns; | ||
| + | } | ||
| + | | ||
| + | $parts = explode(':', | ||
| + | while (count($parts) > 1) { | ||
| + | array_pop($parts); | ||
| + | $parentNs = implode(':', | ||
| + | if (!empty($parentNs)) { | ||
| + | $hierarchy[] = $parentNs; | ||
| + | } | ||
| + | } | ||
| + | | ||
| + | $hierarchy[] = ''; | ||
| + | | ||
| + | return $hierarchy; | ||
| + | } | ||
| + | |||
| + | /** | ||
| + | * Extraire le namespace du chemin | ||
| + | * @param string $path | ||
| + | * @return string | ||
| + | */ | ||
| + | protected function _extractNamespaceFromPath($path) { | ||
| + | $cleanPath = trim($path, ':' | ||
| + | $parts = explode(':', | ||
| + | array_pop($parts); | ||
| + | | ||
| + | return implode(' | ||
| + | } | ||
| + | } | ||
| + | ?> | ||
| + | </ | ||
| + | </ | ||
| + | <adm question style.less> | ||
| + | <code cpp> | ||
| + | /* Container du logo namespace */ | ||
| + | .ns-logo-container { | ||
| + | margin: 1em 0; | ||
| + | text-align: center; | ||
| + | padding: 0.5em; | ||
| + | } | ||
| + | |||
| + | /* Image du logo */ | ||
| + | .ns-logo { | ||
| + | max-width: 200px; | ||
| + | max-height: 100px; | ||
| + | height: auto; | ||
| + | width: auto; | ||
| + | display: inline-block; | ||
| + | } | ||
| + | |||
| + | /* Responsive */ | ||
| + | @media screen and (max-width: 768px) { | ||
| + | .ns-logo { | ||
| + | max-width: 150px; | ||
| + | max-height: 80px; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | /* Indicateur visuel du fallback (optionnel) */ | ||
| + | .ns-logo-container.fallback-parent { | ||
| + | border-left: | ||
| + | padding-left: | ||
| + | } | ||
| + | </ | ||
| + | </ | ||
| + | ---- | ||
| + | |||
| + | ===== Fonctionnalités intégrées ===== | ||
| + | |||
| + | |||
lumo/creation_plugin_dokuwiki_namespacelogo/accueil.1773681225.txt.gz · Dernière modification : de estro
