default_options = &$default_options;
// init
$this->options = $this->default_options;
}
function PluginSplitbody() {
$this->__construct();
}
function convert()
{
// arguments
if (func_num_args() === 0) { return; }
$args = func_get_args();
$body = array_pop($args);
$body = str_replace("\r", "\n", $body);
foreach ($args as $arg) {
list($key, $val) = array_pad(explode('=', $arg, 2), 2, true);
$this->options[$key] = $val;
}
$this->options['style'] = htmlsc($this->options['style']);
$this->options['width'] = htmlsc($this->options['width']);
// main
list($bodies, $splitargs) = $this->splitbody($body);
$splitoptions = array();
foreach ($splitargs as $i => $splitarg) {
$splitoptions[$i] = array();
foreach ($splitarg as $arg) {
list($key, $val) = array_pad(explode('=', $arg, 2), 2, true);
$splitoptions[$i][$key] = htmlsc($val);
}
}
if ($this->options['tag'] == 'table') {
$output = $this->table($bodies, $splitoptions);
} else {
$output = $this->div($bodies, $splitoptions);
}
return $output;
}
function table(&$bodies, &$splitoptions)
{
$num = count($bodies);
$border = $this->options['border'] === true ? $this->border : '';
$width = $this->options['width'];
$colstyle = $this->options['style'];
$colwidth = intval(100 / $num) . '%';
$html = '
' . "\n";
for ($i = 0; $i < $num; $i++) {
$body = $bodies[$i];
$width = isset($splitoptions[$i]['width']) ? $splitoptions[$i]['width'] : $colwidth;
$style = isset($splitoptions[$i]['style']) ? $splitoptions[$i]['style'] : $colstyle;
$html .= '' . "\n";
$html .= convert_html($body);
$html .= ' | ' . "\n";
}
$html .= '
' . "\n";
return $html;
}
function div(&$bodies, &$splitoptions)
{
$num = count($bodies);
$border = $this->options['border'] === true ? $this->border : '';
$width = $this->options['width'];
$colwidth = intval(96 / $num) . '%'; // 96%....
$colstyle = $this->options['style'];
$html = '' . "\n";
for ($i = 0; $i < $num; $i++) {
$body = $bodies[$i];
$width = isset($splitoptions[$i]['width']) ? $splitoptions[$i]['width'] : $colwidth;
$style = isset($splitoptions[$i]['style']) ? $splitoptions[$i]['style'] : $colstyle;
$html .= '
' . "\n";
$html .= convert_html($body);
$html .= '
' . "\n";
}
$html .= '
' . "\n";
$html .= '
' . "\n";
return $html;
}
function splitbody(&$body)
{
$lines = explode("\n", $body);
$splitargs = array();
$bodies = array();
$line = current($lines);
$matches = array();
if (preg_match('/' . $this->splittag . '(?:\(([^)]*)\))?(.*)$/', $line, $matches)) {
$splitargs[] = csv_explode(',', $matches[1]);
$bodies[0] = '';
} else {
$bodies[0] = $line . "\n";
}
$i = 0;
while (($line = next($lines)) !== false) {
$matches = array();
if (preg_match('/' . $this->splittag . '(?:\(([^)]*)\))?(.*)$/', $line, $matches)) {
$splitargs[] = csv_explode(',', $matches[1]);
$bodies[++$i] = '';
} else {
$bodies[$i] .= $line . "\n";
}
}
if (count($bodies) > count($splitargs)) {
array_unshift($splitargs, array());
}
return array(&$bodies, &$splitargs);
}
}
function plugin_splitbody_common_init()
{
global $plugin_splitbody;
if (class_exists('PluginSplitbodyUnitTest')) {
$plugin_splitbody = new PluginSplitbodyUnitTest();
} elseif (class_exists('PluginSplitbodyUser')) {
$plugin_splitbody = new PluginSplitbodyUser();
} else {
$plugin_splitbody = new PluginSplitbody();
}
}
function plugin_splitbody_convert()
{
global $plugin_splitbody; plugin_splitbody_common_init();
$args = func_get_args();
return call_user_func_array(array(&$plugin_splitbody, 'convert'), $args);
}
?>