1<?php 2/** 3 * DokuWiki Plugin struct (Action Component) 4 * 5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6 * @author Andreas Gohr, Michael Große <dokuwiki@cosmocode.de> 7 */ 8 9// must be run within Dokuwiki 10use dokuwiki\plugin\struct\meta\Assignments; 11use dokuwiki\plugin\struct\meta\SchemaData; 12 13if(!defined('DOKU_INC')) die(); 14 15class action_plugin_struct_search extends DokuWiki_Action_Plugin { 16 17 /** 18 * Registers a callback function for a given event 19 * 20 * @param Doku_Event_Handler $controller DokuWiki's event controller object 21 * @return void 22 */ 23 public function register(Doku_Event_Handler $controller) { 24 $controller->register_hook('INDEXER_PAGE_ADD', 'BEFORE', $this, 'handle_indexing'); 25 $controller->register_hook('FULLTEXT_SNIPPET_CREATE', 'BEFORE', $this, 'handle_snippets'); 26 } 27 28 /** 29 * Adds the structured data to the page body to be indexed 30 * 31 * @param Doku_Event $event event object by reference 32 * @param mixed $param [the parameters passed as fifth argument to register_hook() when this 33 * handler was registered] 34 * @return bool 35 */ 36 public function handle_indexing(Doku_Event $event, $param) { 37 $id = $event->data['page']; 38 $assignments = new Assignments(); 39 $tables = $assignments->getPageAssignments($id); 40 if(!$tables) return; 41 42 foreach($tables as $table) { 43 $schemadata = new SchemaData($table, $id, 0); 44 $event->data['body'] .= $schemadata->getDataPseudoSyntax(); 45 } 46 } 47 48 /** 49 * Adds the structured data to the page body to be snippeted 50 * 51 * @param Doku_Event $event event object by reference 52 * @param mixed $param [the parameters passed as fifth argument to register_hook() when this 53 * handler was registered] 54 * @return bool 55 */ 56 public function handle_snippets(Doku_Event $event, $param) { 57 $id = $event->data['id']; 58 $assignments = new Assignments(); 59 $tables = $assignments->getPageAssignments($id); 60 if(!$tables) return; 61 62 foreach($tables as $table) { 63 $schemadata = new SchemaData($table, $id, 0); 64 $event->data['text'] .= $schemadata->getDataPseudoSyntax(); 65 } 66 } 67} 68 69// vim:ts=4:sw=4:et: 70