xref: /plugin/combo/action/metatitle.php (revision 007225e5fb2d3f64edaccd3bd447ca26effb9d68)
1<?php
2
3
4
5/**
6 * Class action_plugin_combo_metatitle
7 * Set and manage the meta title
8 * The event is triggered in the strap template
9 */
10class action_plugin_combo_metatitle extends DokuWiki_Action_Plugin
11{
12
13    const TITLE_META_KEY = "title";
14
15    public function register(Doku_Event_Handler $controller)
16    {
17        $controller->register_hook('TPL_TITLE_OUTPUT', 'BEFORE', $this, 'handleTitle', array());
18    }
19
20    function handleTitle(&$event, $param)
21    {
22        $event->data = self::getTitle();
23    }
24
25    static function getTitle(){
26        global $ID;
27        global $conf;
28        if (defined('DOKU_UNITTEST')) {
29            $title = TestUtility::getMeta($ID, self::TITLE_META_KEY);
30        } else {
31            $title = p_get_metadata($ID, self::TITLE_META_KEY);
32        }
33        if (!empty($title)){
34
35            $pageTitle = $title;
36
37        } else {
38
39            // Home page
40            if ($ID == "start") {
41                $pageTitle = $conf["title"];
42                if ($conf['tagline']) {
43                    $pageTitle .= ' - ' . $conf['tagline'];
44                }
45            } else {
46                $pageTitle = tpl_pagetitle($ID, true) . ' ['. $conf["title"]. ']';
47            }
48
49        }
50        return strip_tags($pageTitle);
51    }
52}
53