1<?php 2/** 3 * Keywords Plugin 4 * 5 * Specifies keywords list for the page 6 * 7 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 8 * @author Ilya Lebedev <ilya@lebedev.net> 9 */ 10 11// must be run within Dokuwiki 12if(!defined('DOKU_INC')) die(); 13 14if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 15require_once(DOKU_PLUGIN.'syntax.php'); 16 17/** 18 * All DokuWiki plugins to extend the parser/rendering mechanism 19 * need to inherit from this class 20 */ 21class syntax_plugin_keywords_keywords extends DokuWiki_Syntax_Plugin { 22 23 function getType(){ return 'substition'; } 24 function getPType(){ return 'block'; } 25 function getSort(){ return 110; } 26 27 /** 28 * Connect pattern to lexer 29 */ 30 function connectTo($mode){ 31 if ($mode == 'base'){ 32 $this->Lexer->addSpecialPattern('{{keywords>.+?}}',$mode,'plugin_keywords_keywords'); 33 } 34 } 35 /** 36 * Handle the match 37 */ 38 function handle($match, $state, $pos, Doku_Handler $handler){ 39 return explode(",",preg_replace("/{{keywords>(.*?)}}/","\\1",$match)); 40 } 41 42 /** 43 * Render output 44 */ 45 function render($mode, Doku_Renderer $renderer, $data) { 46 switch ($mode) { 47 case 'metadata' : 48 /* 49 * mark metadata with found value 50 */ 51 $data = array_map( 'trim', $data ?: [] ); 52 $renderer->meta['keywords'] = ", " . join(', ', $data); 53 return true; 54 break; 55 } 56 return false; 57 } 58} 59