1<?php
2/**
3 *  Description action plugin
4 *
5 *  @lastmodified 2012-07-02
6 *  @license      GPL 2 (http://www.gnu.org/licenses/gpl.html)
7 *  @author       Ikuo Obataya <I.Obataya@gmail.com>
8 *  @author       Matthias Schulte <dokuwiki@lupo49.de>
9 *  @version      2012-07-02
10 */
11
12if(!defined('DOKU_INC')) die();
13if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
14
15require_once(DOKU_PLUGIN.'action.php');
16
17define('KEYWORD_SOURCE_ABSTRACT', 'abstract');
18define('KEYWORD_SOURCE_GLOBAL', 'global');
19define('KEYWORD_SOURCE_SYNTAX', 'syntax');
20
21class action_plugin_description extends DokuWiki_Action_Plugin {
22
23    function register(Doku_Event_Handler $controller) {
24        $controller->register_hook('TPL_METAHEADER_OUTPUT','BEFORE',$this,'description',array());
25    }
26
27    /**
28     * Add an abstract, global value or a specified string to meta header
29     */
30    function description(&$event, $param) {
31        if(empty($event->data) || empty($event->data['meta'])) return;
32
33        global $ID;
34        $source = $this->getConf('keyword_source');
35        if(empty($source)) $source = 'abstract';
36
37        if($source == KEYWORD_SOURCE_ABSTRACT) {
38            $d = p_get_metadata($ID, 'description');
39            if(empty($d)) return;
40
41            $a = str_replace("\n", " ", $d['abstract']);
42            if(empty($a)) return;
43        }
44
45        if($source == KEYWORD_SOURCE_GLOBAL) {
46            $a = $this->getConf('global_description');
47            if(empty($a)) return;
48        }
49
50        if($source == KEYWORD_SOURCE_SYNTAX) {
51            $metadata = p_get_metadata($ID);
52            $a = $metadata['plugin_description']['keywords'];
53            if(empty($a)) return;
54        }
55
56        $m = array("name" => "description", "content" => $a);
57        $event->data['meta'][] = $m;
58    }
59}
60