1<?php 2/** 3 * Table2Csv Action Plugin 4 * 5 * Provides export of table to csv 6 * 7 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 8 * @author Tom Cafferty <tcafferty@glocalfocal.com> 9 */ 10 11// must be run within Dokuwiki 12if(!defined('DOKU_INC')) die(); 13if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 14require_once DOKU_PLUGIN.'action.php'; 15 16class action_plugin_table2csv extends DokuWiki_Action_Plugin { 17 18 function getInfo() { 19 return array( 20 'author' => 'Tom Cafferty', 21 'email' => 'tcafferty@glocalfocal.com', 22 'date' => '2012-07-22', 23 'name' => 'table2csv', 24 'desc' => 'export table on page to csv file', 25 'url' => 'http://www.dokuwiki.org/plugin:table2csv' 26 ); 27 } 28 29 /** 30 * Register its handlers with the DokuWiki's event controller 31 */ 32 function register(&$controller) { 33 $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'convert2csv',array()); 34 } 35 36 /** 37 * convert script for csv file output. 38 * 39 * @author Tom Cafferty <tcafferty@glocalfocal.com> 40 */ 41 function convert2csv(&$event, $param) { 42 global $ACT; 43 global $ID; 44 global $conf; 45 46 // our event? 47 if ($ACT != 'export_csv' ) return false; 48 49 // check user's rights 50 if ( auth_quickaclcheck($ID) < AUTH_READ ) { 51 msg(sprintf('Forbidden access to page ' . $ID)); 52 return false; 53 } 54 55 // it's ours, no one else's 56 require_once ('getTableData.php'); 57 $event->preventDefault(); 58 59 //get start marker 60 $sm = p_get_metadata($ID,'table2csv'); 61 62 // get page data 63 $fileext = $this->getConf('filepath'); 64 $html = scrapeTable2Csv($ID,$fileext,$sm); 65 66 if ($html === false) { 67 return false; 68 } else { 69 // remain on current page 70 header("HTTP/1.1 204 No Content"); 71 exit(); 72 } 73 } 74}