* @version $Revision$ * @package liberty * @subpackage plugins_data * @copyright Copyright (c) 2004, bitweaver.org * All Rights Reserved. See below for details and a complete list of authors. * @license Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details. */ /****************** * Initialization * ******************/ define( 'PLUGIN_GUID_DATALEDGERTABLE', 'dataledgertable' ); global $gLibertySystem; $pluginParams = [ 'tag' => 'LEDGERTABLE', 'auto_activate' => false, 'requires_pair' => true, 'load_function' => '\data_ledgertable', 'title' => 'Ledger Table', 'help_page' => 'DataPluginLedgertable', 'description' => KernelTools::tra("This Plugin creates a ledger-like table with even/odd row colors, optional top- or left-placed headers, and support for row/column spans."), 'help_function' => '\data_ledgertable_help', 'syntax' => "{LEDGERTABLE loc= head= }", 'plugin_type' => DATA_PLUGIN, ]; $gLibertySystem->registerPlugin( PLUGIN_GUID_DATALEDGERTABLE, $pluginParams ); $gLibertySystem->registerDataTag( $pluginParams['tag'], PLUGIN_GUID_DATALEDGERTABLE ); /***************** * Help Function * *****************/ function data_ledgertable_help() { $help = '' .'' .'' .'' .'' .'' .'' .'' .'' .'' .'' .'' .'' .'' .'' .'' .'
' . KernelTools::tra( "Key" ) . '' . KernelTools::tra( "Type" ) . '' . KernelTools::tra( "Comments" ) . '
loc' . KernelTools::tra( "string") . '
' . KernelTools::tra("(optional)") . '
' . KernelTools::tra( "Where to display row/column headers (\"left\" or \"top\", default top).") .'
head' . KernelTools::tra( "string") . '
' . KernelTools::tra("(optional)") . '
' . KernelTools::tra( "Header(s) separated by \"~|~\", default none") .'
' . KernelTools::tra("LedgerTable: ") . "{LEDGERTABLE loc=>left head=>Row1~|~Row2~|~Row3}
" . KernelTools::tra("This will display") . data_ledgertable('Example', ['loc' => 'left', 'head' => 'Row1~|~Row2~|~Row3']); return $help; } /**************** * Load Function * ****************/ function data_ledgertable($data, $params) { global $gBitSystem; if (empty($data)) { return ""; } if (substr($data, 0, 1) == "\n") { $data = substr($data, 1); } $ret = ''; if (isset($params['loc'])) { $ret .= ""; $plugdata_loc = $params['loc']; } else { $ret .= ""; $plugdata_loc = 'top'; } if (isset($params['head'])) { $ret .= ""; $plugdata_head = $params['head']; } else { $ret .= ""; } if (isset($params['width'])) { $ret .= ""; $plugdata_width = " style=\"width: " . $params['width'] . '"'; } else { $plugdata_width = ""; } $ret .= ""; if (isset($plugdata_head)) { $headers = explode('~|~', $plugdata_head); if ($plugdata_loc == 'top') { $ret .= " "; $ret .= " "; foreach ($headers as $hdr) { $ret .= " "; } } $lines = mb_split("\n", $data); $line_count = 0; foreach ($lines as $line) { $line = trim($line); if (strlen($line) <= 0) { continue; } $line_count++; $ret .= " "; $ret .= " "; if (isset($plugdata_head) && ($plugdata_loc == "left")) { $ret .= " "; $ret .= "
$hdr"; } $ret .= "