xref: /plugin/combo/action/autofrontmatter.php (revision 04fd306c7c155fa133ebb3669986875d65988276)
1c25e802bSgerardnico<?php
2c25e802bSgerardnico
3*04fd306cSNickeauuse ComboStrap\ExceptionCompile;
4*04fd306cSNickeauuse ComboStrap\LogUtility;
5*04fd306cSNickeauuse ComboStrap\MarkupPath;
6c25e802bSgerardnico
7c25e802bSgerardnico/**
8c25e802bSgerardnico * Copyright (c) 2021. ComboStrap, Inc. and its affiliates. All Rights Reserved.
9c25e802bSgerardnico *
10c25e802bSgerardnico * This source code is licensed under the GPL license found in the
11c25e802bSgerardnico * COPYING  file in the root directory of this source tree.
12c25e802bSgerardnico *
13c25e802bSgerardnico * @license  GPL 3 (https://www.gnu.org/licenses/gpl-3.0.en.html)
14c25e802bSgerardnico * @author   ComboStrap <support@combostrap.com>
15c25e802bSgerardnico *
16c3437056SNickeau *
17c3437056SNickeau * @deprecated - the frontmatter is no more used to enter metadata.
18c25e802bSgerardnico */
19c25e802bSgerardnicoclass action_plugin_combo_autofrontmatter extends DokuWiki_Action_Plugin
20c25e802bSgerardnico{
21c25e802bSgerardnico
22c25e802bSgerardnico
23c25e802bSgerardnico    public function register(Doku_Event_Handler $controller)
24c25e802bSgerardnico    {
25c25e802bSgerardnico        /**
26c25e802bSgerardnico         * Called when new page is created
27c25e802bSgerardnico         * In order to set its content
28c25e802bSgerardnico         * https://www.dokuwiki.org/devel:event:common_pagetpl_load
29c25e802bSgerardnico         */
30c3437056SNickeau        if (false) {
31c25e802bSgerardnico            $controller->register_hook('COMMON_PAGETPL_LOAD', 'BEFORE', $this, 'handle_new_page', array());
32c25e802bSgerardnico        }
33c25e802bSgerardnico    }
34c25e802bSgerardnico
35c25e802bSgerardnico    public function handle_new_page(Doku_Event $event, $param){
36c25e802bSgerardnico
37*04fd306cSNickeau        try {
38*04fd306cSNickeau            $page = MarkupPath::createPageFromExecutingId();
39*04fd306cSNickeau        } catch (ExceptionCompile $e) {
40*04fd306cSNickeau            LogUtility::msg("Unable to handle a new page because the global id is unknown");
41*04fd306cSNickeau        }
42c3437056SNickeau        $canonical = $page->getCanonicalOrDefault();
43c25e802bSgerardnico        $event->data["tpl"] = <<<EOF
44c25e802bSgerardnico---json
45c25e802bSgerardnico{
46c25e802bSgerardnico    "canonical":"{$canonical}",
47e06795b8Sgerardnico    "title":"A [[https://combostrap.com/frontmatter|frontmatter]] title shown on the Search Engine Result Pages",
48e06795b8Sgerardnico    "description":"A [[https://combostrap.com/frontmatter|frontmatter]] description shown on the Search Engine Result Pages"
49c25e802bSgerardnico}
50c25e802bSgerardnico---
51c25e802bSgerardnicoEOF;
52c25e802bSgerardnico
53c25e802bSgerardnico
54c25e802bSgerardnico    }
55c25e802bSgerardnico}
56c25e802bSgerardnico
57c25e802bSgerardnico
58c25e802bSgerardnico
59