1<?php 2 3use ComboStrap\LogUtility; 4use ComboStrap\Page; 5 6 7/** 8 * Take the metadata description 9 * 10 */ 11 12 13class action_plugin_combo_metadescription extends DokuWiki_Action_Plugin 14{ 15 16 const DESCRIPTION_META_KEY = 'description'; 17 const DESCRIPTION_PROPERTY = 'og:description'; 18 19 public function register(Doku_Event_Handler $controller) 20 { 21 $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'description_modification', array()); 22 } 23 24 /** 25 * Add a meta-data description 26 * @param $event 27 * @param $param 28 */ 29 function description_modification(&$event, $param) 30 { 31 32 global $ID; 33 if (empty($ID)) { 34 return; // Admin call for instance 35 } 36 37 /** 38 * Description 39 * https://www.dokuwiki.org/devel:metadata 40 */ 41 $page = Page::createPageFromId($ID); 42 43 $description = $page->getDescriptionOrElseDokuWiki(); 44 if (empty($description)) { 45 $this->sendDestInfo($ID); 46 return; 47 } 48 49 // Add it to the meta 50 $event->data['meta'][] = array("name" => self::DESCRIPTION_META_KEY, "content" => $description); 51 $event->data['meta'][] = array("property" => self::DESCRIPTION_PROPERTY, "content" => $description); 52 53 54 } 55 56 /** 57 * Just send a test info 58 * @param $ID 59 */ 60 public function sendDestInfo($ID) 61 { 62 if (defined('DOKU_UNITTEST')) { 63 // When you make a admin test call, the page ID = start and there is no meta 64 // When there is only an icon, there is also no meta 65 global $INPUT; 66 $showActions = ["show", ""]; // Empty for the test 67 if (in_array($INPUT->str("do"), $showActions)) { 68 LogUtility::msg("Page ($ID): The description should never be null when rendering the page", LogUtility::LVL_MSG_INFO); 69 } 70 } 71 } 72 73 74} 75