1<?php 2 3use ComboStrap\LdJson; 4use ComboStrap\Page; 5use ComboStrap\PluginUtility; 6 7 8require_once(__DIR__ . '/../ComboStrap/PluginUtility.php'); 9 10 11class action_plugin_combo_metagoogle extends DokuWiki_Action_Plugin 12{ 13 14 15 const CANONICAL = "google"; 16 const PUBLISHER = "publisher"; 17 18 function __construct() 19 { 20 // enable direct access to language strings 21 // ie $this->lang 22 $this->setupLocale(); 23 } 24 25 public function register(Doku_Event_Handler $controller) 26 { 27 $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'metaGoogleProcessing', array()); 28 } 29 30 /** 31 * 32 * @param $event 33 */ 34 function metaGoogleProcessing($event) 35 { 36 37 38 if(!PluginUtility::isRenderingRequestedPageProcess()){ 39 return; 40 } 41 42 $page = Page::createPageFromRequestedPage(); 43 $ldJson = LdJson::createForPage($page) 44 ->getLdJsonMergedWithDefault(); 45 46 /** 47 * Publish 48 */ 49 if (!empty($ldJson)) { 50 $event->data["script"][] = array( 51 "type" => "application/ld+json", 52 "_data" => $ldJson, 53 ); 54 } 55 } 56 57 58} 59