xref: /plugin/struct/action/title.php (revision 7cbcfbdb68125878b37fede99d5e33997295c2f6)
11c9ef013SAndreas Gohr<?php
21c9ef013SAndreas Gohr/**
31c9ef013SAndreas Gohr * DokuWiki Plugin struct (Action Component)
41c9ef013SAndreas Gohr *
51c9ef013SAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
61c9ef013SAndreas Gohr * @author  Andreas Gohr, Michael Große <dokuwiki@cosmocode.de>
71c9ef013SAndreas Gohr */
81c9ef013SAndreas Gohr
91c9ef013SAndreas Gohr// must be run within Dokuwiki
10*7cbcfbdbSAndreas Gohruse dokuwiki\plugin\struct\meta\StructException;
111c9ef013SAndreas Gohruse dokuwiki\plugin\struct\meta\Title;
121c9ef013SAndreas Gohr
131c9ef013SAndreas Gohrif(!defined('DOKU_INC')) die();
141c9ef013SAndreas Gohr
151c9ef013SAndreas Gohr/**
161c9ef013SAndreas Gohr * Class action_plugin_struct_title
171c9ef013SAndreas Gohr *
181c9ef013SAndreas Gohr * Saves the page title when meta data is saved
191c9ef013SAndreas Gohr */
201c9ef013SAndreas Gohrclass action_plugin_struct_title extends DokuWiki_Action_Plugin {
211c9ef013SAndreas Gohr
221c9ef013SAndreas Gohr    /**
231c9ef013SAndreas Gohr     * Registers a callback function for a given event
241c9ef013SAndreas Gohr     *
251c9ef013SAndreas Gohr     * @param Doku_Event_Handler $controller DokuWiki's event controller object
261c9ef013SAndreas Gohr     * @return void
271c9ef013SAndreas Gohr     */
281c9ef013SAndreas Gohr    public function register(Doku_Event_Handler $controller) {
291c9ef013SAndreas Gohr        $controller->register_hook('PARSER_METADATA_RENDER', 'AFTER', $this, 'handle_meta');
301c9ef013SAndreas Gohr    }
311c9ef013SAndreas Gohr
321c9ef013SAndreas Gohr    /**
331c9ef013SAndreas Gohr     * Store the page's title
341c9ef013SAndreas Gohr     *
351c9ef013SAndreas Gohr     * @param Doku_Event $event
361c9ef013SAndreas Gohr     * @param $param
371c9ef013SAndreas Gohr     */
381c9ef013SAndreas Gohr    public function handle_meta(Doku_Event $event, $param) {
391c9ef013SAndreas Gohr        $id = $event->data['current']['last_change']['id'];
40*7cbcfbdbSAndreas Gohr        try {
411c9ef013SAndreas Gohr            $title = new Title($id);
421c9ef013SAndreas Gohr
431c9ef013SAndreas Gohr            if(!blank($event->data['current']['title'])) {
441c9ef013SAndreas Gohr                $title->setTitle($event->data['current']['title']);
451c9ef013SAndreas Gohr            } else {
461c9ef013SAndreas Gohr                $title->setTitle(null);
471c9ef013SAndreas Gohr            }
48*7cbcfbdbSAndreas Gohr        } catch(StructException $e) {
49*7cbcfbdbSAndreas Gohr            msg($e->getMessage(), -1);
50*7cbcfbdbSAndreas Gohr        }
511c9ef013SAndreas Gohr    }
521c9ef013SAndreas Gohr
531c9ef013SAndreas Gohr}
54