. * */ /* Required library for main process */ include 'WikiTable.php'; /* Initialize form variables */ $input = getPostVariable('input'); $cellStyle = getPostVariable('cell_style'); $headerColumnStyle = getPostVariable('header_column_style'); $otherCellStyle = getPostVariable('other_cell_style'); $otherRowStyle = getPostVariable('other_row_style'); $headerRowStyle = getPostVariable('header_row_style'); $rowStyle = getPostVariable('row_style'); $caption = getPostVariable('caption'); $tableStyle = getPostVariable('table_style'); $columnHeader = getPostCheckboxVariable('column_header'); $rowHeader = getPostCheckboxVariable('row_header'); $booleanColumnHeader = $columnHeader == 'checked'; $booleanRowHeader = $rowHeader == 'checked'; /* Instantiate WikiTable object */ $wikiTable = new WikiTable($input); /* Set various styling features according to form variables */ $wikiTable->setCellStyle($cellStyle); $wikiTable->setColumnHeaderStyle($headerColumnStyle); $wikiTable->setOtherCellStyle($otherCellStyle); $wikiTable->setOtherRowStyle($otherRowStyle); $wikiTable->setRowHeaderStyle($headerRowStyle); $wikiTable->setRowStyle($rowStyle); $wikiTable->setTableCaption($caption); $wikiTable->setTableStyle($tableStyle); $wikiTable->setColumnHeader($booleanColumnHeader); $wikiTable->setRowHeader($booleanRowHeader); /* Get the final output table */ $wikiTableOutput = $wikiTable->get(); /* Main output */ $html = << Google Spreadsheet/Excel to MediaWiki table format

Google Spreadsheet/Excel to MediaWiki table format

Paste the input table HERE

First column header
First row header
Table caption (leave empty for no caption)
Table style (i.e. <table *HERE*>...</table>)
Row style (i.e. <tr *HERE*>...</tr>)
Cell style (i.e. <td *HERE*>...</td>)
Every other row style (optional for even-odd patterns)
Every other cell style (optional for even-odd patterns)
Cell style for header column
Cell style for header row

Resulting source code:

{$wikiTableOutput}
HEREDOC; /* Outputs the GUI Screen*/ echo $html; /** * Determines the correct value for each form value. * Priority: (1) $_POST (2) Default (3) Empty * * @staticvar array $defaults * @param string $variable * @return string */ function getPostVariable($variable) { static $defaults = array( 'cell_style' => '', 'header_column_style' => '', 'other_cell_style' => '', 'other_row_style' => '', 'header_row_style' => '', 'row_style' => '', 'caption' => '', 'table_style' => 'class=\'wikitable\'', 'input' => '', ); if(isset($_POST[$variable]) && !empty($_POST[$variable])) return $_POST[$variable]; elseif(isset($defaults[$variable])) return $defaults[$variable]; else return ''; } /** * SPECIAL CASE FOR CHECKBOXES, since they behave differently. * Determines the correct value for each form value. * Priority: (1) $_POST (2) Default (3) Empty * * @staticvar array $defaults * @param string $variable * @return string */ function getPostCheckboxVariable($variable) { static $defaults = array( 'column_header' => 'checked', 'row_header' => '', ); if(empty($_POST) && isset($defaults[$variable])) return $defaults[$variable]; elseif(!empty($_POST) && !isset($_POST[$variable]) || empty($_POST) && !isset($defaults[$variable])) return ''; else return 'checked'; }