1<?php 2 3use ComboStrap\Page; 4 5/** 6 * Copyright (c) 2021. ComboStrap, Inc. and its affiliates. All Rights Reserved. 7 * 8 * This source code is licensed under the GPL license found in the 9 * COPYING file in the root directory of this source tree. 10 * 11 * @license GPL 3 (https://www.gnu.org/licenses/gpl-3.0.en.html) 12 * @author ComboStrap <support@combostrap.com> 13 * 14 */ 15 16class action_plugin_combo_autofrontmatter extends DokuWiki_Action_Plugin 17{ 18 19 const CONF_AUTOFRONTMATTER_ENABLE = "autoFrontMatterEnable"; 20 21 public function register(Doku_Event_Handler $controller) 22 { 23 /** 24 * Called when new page is created 25 * In order to set its content 26 * https://www.dokuwiki.org/devel:event:common_pagetpl_load 27 */ 28 if ($this->getConf(self::CONF_AUTOFRONTMATTER_ENABLE)) { 29 $controller->register_hook('COMMON_PAGETPL_LOAD', 'BEFORE', $this, 'handle_new_page', array()); 30 } 31 } 32 33 public function handle_new_page(Doku_Event $event, $param){ 34 35 global $ID; 36 $page = new Page($ID); 37 $canonical = $page->getCanonical(); 38 $event->data["tpl"] = <<<EOF 39---json 40{ 41 "canonical":"{$canonical}", 42 "title":"A title to show on the Search Engine Result Pages", 43 "description":"A description show on the Search Engine Result Pages" 44} 45--- 46This content was created by the [[https://combostrap.com/frontmatter|frontmatter component]]. 47EOF; 48 49 50 } 51} 52 53 54 55