1<?php 2/** 3 * DokuWiki Plugin tablelayout (Action Component) 4 * 5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6 * @author Michael Große <dokuwiki@cosmocode.de> 7 */ 8 9// must be run within Dokuwiki 10if (!defined('DOKU_INC')) { 11 die(); 12} 13 14/** 15 * Class action_plugin_tablelayout_print 16 * 17 * Handles the adjusted tablelayout strings from edittable 18 */ 19class action_plugin_tablelayout_print extends DokuWiki_Action_Plugin 20{ 21 public function register(Doku_Event_Handler $controller) 22 { 23 $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'allowTablelayoutPrint'); 24 $controller->register_hook('TPL_ACT_UNKNOWN', 'BEFORE', $this, 'printTable'); 25 } 26 27 public function allowTablelayoutPrint(Doku_Event $event, $param) 28 { 29 if ($event->data !== 'tablelayout_printtable') { 30 return; 31 } 32 global $ID; 33 if (auth_quickaclcheck($ID) < AUTH_READ) { 34 msg('Not Authorized for page ' . hsc($ID), -1); 35 $event->data = 'show'; 36 return; 37 } 38 $event->preventDefault(); 39 } 40 41 public function printTable(Doku_Event $event, $param) 42 { 43 if ($event->data !== 'tablelayout_printtable') { 44 return; 45 } 46 $event->preventDefault(); 47 global $INPUT, $ID; 48 list(, $table, ) = rawWikiSlices($INPUT->str('range'), $ID); 49 echo '<span id="tablelayout_printthis"></span>'; 50 51 // pass layout to javascript, so that it can apply column width styles 52 if ($INPUT->str('colwidth')) { 53 $json = hsc( 54 json_encode( 55 [ 56 'colwidth' => explode(',', $INPUT->str('colwidth')), 57 ] 58 ) 59 ); 60 echo "<div class='plugin_tablelayout_placeholder' data-tablelayout=\"$json\"></div>"; 61 } 62 63 echo p_render('xhtml', p_get_instructions($table), $info); 64 } 65} 66