xref: /plugin/struct/action/title.php (revision 88b58a212b1e27877882d9dad769a4d01cffdde4)
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
107cbcfbdbSAndreas Gohruse dokuwiki\plugin\struct\meta\StructException;
113aad9612SMichael Grosseuse dokuwiki\plugin\struct\meta\PageMeta;
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) {
39a7cffaf2SAndreas Gohr        $id = $event->data['page'];
40a7cffaf2SAndreas Gohr
417cbcfbdbSAndreas Gohr        try {
423aad9612SMichael Grosse            $page = new PageMeta($id);
431c9ef013SAndreas Gohr
441c9ef013SAndreas Gohr            if(!blank($event->data['current']['title'])) {
45109edca8SMichael Grosse                $page->setTitle($event->data['current']['title']);
461c9ef013SAndreas Gohr            } else {
47109edca8SMichael Grosse                $page->setTitle(null);
48109edca8SMichael Grosse            }
49109edca8SMichael Grosse
50109edca8SMichael Grosse            if(!blank($event->data['current']['last_change']['date'])) {
51109edca8SMichael Grosse                $page->setLastRevision($event->data['current']['last_change']['date']);
52109edca8SMichael Grosse            } else {
53109edca8SMichael Grosse                $page->setLastRevision(null);
54109edca8SMichael Grosse            }
55109edca8SMichael Grosse
56109edca8SMichael Grosse            if(!blank($event->data['current']['last_change']['user'])) {
57109edca8SMichael Grosse                $page->setLastEditor($event->data['current']['last_change']['user']);
58109edca8SMichael Grosse            } elseif (!blank($event->data['current']['last_change']['ip'])) {
599abde7b5SMichael Grosse                $page->setLastEditor($event->data['current']['last_change']['ip']);
60109edca8SMichael Grosse            } else {
61109edca8SMichael Grosse                $page->setLastEditor(null);
621c9ef013SAndreas Gohr            }
63*88b58a21SSzymon Olewniczak
64*88b58a21SSzymon Olewniczak            if(!blank($event->data['current']['last_change']['sum'])) {
65*88b58a21SSzymon Olewniczak                $page->setLastSummary($event->data['current']['last_change']['sum']);
66*88b58a21SSzymon Olewniczak            } else {
67*88b58a21SSzymon Olewniczak                $page->setLastSummary(null);
68*88b58a21SSzymon Olewniczak            }
69*88b58a21SSzymon Olewniczak
708d1ed4ceSMichael Grosse            $page->savePageData();
717cbcfbdbSAndreas Gohr        } catch(StructException $e) {
727cbcfbdbSAndreas Gohr            msg($e->getMessage(), -1);
737cbcfbdbSAndreas Gohr        }
741c9ef013SAndreas Gohr    }
751c9ef013SAndreas Gohr
761c9ef013SAndreas Gohr}
77