1<?php 2 3use ComboStrap\Page; 4use ComboStrap\PluginUtility; 5use ComboStrap\Site; 6 7 8/** 9 * Class action_plugin_combo_metatitle 10 * Set and manage the meta title 11 * The event is triggered in the strap template 12 */ 13class action_plugin_combo_metatitle extends DokuWiki_Action_Plugin 14{ 15 16 17 const TITLE_SEPARATOR = ' | '; 18 19 public function register(Doku_Event_Handler $controller) 20 { 21 $controller->register_hook('TPL_TITLE_OUTPUT', 'BEFORE', $this, 'handleTitle', array()); 22 } 23 24 function handleTitle(&$event, $param) 25 { 26 $event->data = self::getTitle(); 27 } 28 29 static function getTitle(): string 30 { 31 32 // Page Title 33 // Root Home page 34 $currentPage = Page::createPageFromGlobalDokuwikiId(); 35 $pageTitle = $currentPage->getTitleOrDefault(); 36 37 // Namespace name 38 $parentPage = $currentPage->getParentPage(); 39 if($parentPage!=null){ 40 $pageTitle .= self::TITLE_SEPARATOR . $parentPage->getNameOrDefault(); 41 } 42 // Site name 43 if (!empty(Site::getName())) { 44 $pageTitle .= self::TITLE_SEPARATOR . Site::getName(); 45 } 46 47 return PluginUtility::htmlEncode($pageTitle); 48 } 49} 50