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