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 if (auth_quickaclcheck($ID) < AUTH_READ) { 39 // don't add meta header when user has no read permissions 40 return; 41 } 42 43 $d = p_get_metadata($ID, 'description'); 44 if(empty($d)) return; 45 46 $a = str_replace("\n", " ", $d['abstract']); 47 if(empty($a)) return; 48 } 49 50 if($source == KEYWORD_SOURCE_GLOBAL) { 51 $a = $this->getConf('global_description'); 52 if(empty($a)) return; 53 } 54 55 if($source == KEYWORD_SOURCE_SYNTAX) { 56 if (auth_quickaclcheck($ID) < AUTH_READ) { 57 // don't add meta header when user has no read permissions 58 return; 59 } 60 $metadata = p_get_metadata($ID); 61 $a = $metadata['plugin_description']['keywords']; 62 if(empty($a)) return; 63 } 64 65 $m = array("name" => "description", "content" => $a); 66 $event->data['meta'][] = $m; 67 } 68} 69