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