<?php
// PukiWiki - Yet another WikiWikiWeb clone
-// $Id: convert_html.php,v 1.21 2011/01/25 15:01:01 henoheno Exp $
-// Copyright (C)
-// 2002-2005 PukiWiki Developers Team
+// convert_html.php
+// Copyright
+// 2002-2016 PukiWiki Development Team
// 2001-2002 Originally written by yu-ji
// License: GPL v2 or (at your option) any later version
//
if (! is_array($lines)) $lines = explode("\n", $lines);
- $body = & new Body(++$contents_id);
+ $body = new Body(++$contents_id);
$body->parse($lines);
return $body->toString();
function Element()
{
+ $this->__construct();
+ }
+ function __construct()
+ {
$this->elements = array();
$this->last = & $this;
}
{
function Inline($text)
{
- parent::Element();
+ $this->__construct($text);
+ }
+ function __construct($text)
+ {
+ parent::__construct();
$this->elements[] = trim((substr($text, 0, 1) == "\n") ?
$text : make_link($text));
}
function & toPara($class = '')
{
- $obj = & new Paragraph('', $class);
+ $obj = new Paragraph('', $class);
$obj->insert($this);
return $obj;
}
function Paragraph($text, $param = '')
{
- parent::Element();
+ $this->__construct($text, $param);
+ }
+ function __construct($text, $param = '')
+ {
+ parent::__construct();
$this->param = $param;
if ($text == '') return;
function Heading(& $root, $text)
{
- parent::Element();
+ $this->__construct($root, $text);
+ }
+ function __construct(& $root, $text)
+ {
+ parent::__construct();
$this->level = min(3, strspn($text, '*'));
list($text, $this->msg_top, $this->id) = $root->getAnchor($text, $this->level);
{
function HRule(& $root, $text)
{
- parent::Element();
+ $this->__construct($root, $text);
+ }
+ function __construct(& $root, $text)
+ {
+ parent::__construct();
}
function canContain(& $obj)
var $tag2;
var $level;
var $style;
- var $margin;
- var $left_margin;
function ListContainer($tag, $tag2, $head, $text)
{
- parent::Element();
-
- $var_margin = '_' . $tag . '_margin';
- $var_left_margin = '_' . $tag . '_left_margin';
- global $$var_margin, $$var_left_margin;
-
- $this->margin = $$var_margin;
- $this->left_margin = $$var_left_margin;
+ $this->__construct($tag, $tag2, $head, $text);
+ }
+ function __construct($tag, $tag2, $head, $text)
+ {
+ parent::__construct();
$this->tag = $tag;
$this->tag2 = $tag2;
function setParent(& $parent)
{
- global $_list_pad_str;
-
parent::setParent($parent);
$step = $this->level;
if (isset($parent->parent) && is_a($parent->parent, 'ListContainer'))
$step -= $parent->parent->level;
- $margin = $this->margin * $step;
- if ($step == $this->level)
- $margin += $this->left_margin;
-
- $this->style = sprintf($_list_pad_str, $this->level, $margin, $margin);
+ $this->style = sprintf(pkwk_list_attrs_template(), $this->level, $step);
}
function & insert(& $obj)
{
function ListElement($level, $head)
{
- parent::Element();
+ $this->__construct($level, $head);
+ }
+ function __construct($level, $head)
+ {
+ parent::__construct();
$this->level = $level;
$this->head = $head;
}
{
function UList(& $root, $text)
{
- parent::ListContainer('ul', 'li', '-', $text);
+ $this->__construct($root, $text);
+ }
+ function __construct(& $root, $text)
+ {
+ parent::__construct('ul', 'li', '-', $text);
}
}
{
function OList(& $root, $text)
{
- parent::ListContainer('ol', 'li', '+', $text);
+ $this->__construct($root, $text);
+ }
+ function __construct(& $root, $text)
+ {
+ parent::__construct('ol', 'li', '+', $text);
}
}
{
function DList($out)
{
- parent::ListContainer('dl', 'dt', ':', $out[0]);
+ $this->__construct($out);
+ }
+ function __construct($out)
+ {
+ parent::__construct('dl', 'dt', ':', $out[0]);
$this->last = & Element::insert(new ListElement($this->level, 'dd'));
if ($out[1] != '')
$this->last = & $this->last->insert(Factory_Inline($out[1]));
function BQuote(& $root, $text)
{
- parent::Element();
+ $this->__construct($root, $text);
+ }
+ function __construct(& $root, $text)
+ {
+ parent::__construct();
$head = substr($text, 0, 1);
$this->level = min(3, strspn($text, $head));
function TableCell($text, $is_template = FALSE)
{
- parent::Element();
+ $this->__construct($text, $is_template);
+ }
+ function __construct($text, $is_template = FALSE)
+ {
+ parent::__construct();
$this->style = $matches = array();
while (preg_match('/^(?:(LEFT|CENTER|RIGHT)|(BG)?COLOR\(([#\w]+)\)|SIZE\((\d+)\)):(.*)$/',
function Table($out)
{
- parent::Element();
+ $this->__construct($out);
+ }
+ function __construct($out)
+ {
+ parent::__construct();
$cells = explode('|', $out[1]);
$this->col = count($cells);
$is_template = ($this->type == 'c');
$row = array();
foreach ($cells as $cell)
- $row[] = & new TableCell($cell, $is_template);
+ $row[] = new TableCell($cell, $is_template);
$this->elements[] = $row;
}
$row_string = '';
foreach (array_keys($row) as $ncol)
$row_string .= $row[$ncol]->toString();
- $part_string .= $this->wrap($row_string, 'tr');
+ $part_string .= $this->wrap($row_string, 'tr') . "\n";
}
$string .= $this->wrap($part_string, $part);
}
}
}
-// , title1 , title2 , title3
-// , cell1 , cell2 , cell3
-// , cell4 , cell5 , cell6
+// , cell1 , cell2 , cell3
+// , cell4 , cell5 , cell6
+// , cell7 , right,==
+// ,left ,==, cell8
class YTable extends Element
{
- var $col;
-
- function YTable($_value)
- {
- parent::Element();
-
- $align = $value = $matches = array();
- foreach($_value as $val) {
- if (preg_match('/^(\s+)?(.+?)(\s+)?$/', $val, $matches)) {
- $align[] =($matches[1] != '') ?
- ((isset($matches[3]) && $matches[3] != '') ?
- ' style="text-align:center"' :
- ' style="text-align:right"'
- ) : '';
- $value[] = $matches[2];
+ var $col; // Number of columns
+
+ function YTable($row = array('cell1 ', ' cell2 ', ' cell3'))
+ {
+ $this->__construct($row);
+ }
+ // TODO: Seems unable to show literal '==' without tricks.
+ // But it will be imcompatible.
+ // TODO: Why toString() or toXHTML() here
+ function __construct($row = array('cell1 ', ' cell2 ', ' cell3'))
+ {
+ parent::__construct();
+
+ $str = array();
+ $col = count($row);
+
+ $matches = $_value = $_align = array();
+ foreach($row as $cell) {
+ if (preg_match('/^(\s+)?(.+?)(\s+)?$/', $cell, $matches)) {
+ if ($matches[2] == '==') {
+ // Colspan
+ $_value[] = FALSE;
+ $_align[] = FALSE;
+ } else {
+ $_value[] = $matches[2];
+ if ($matches[1] == '') {
+ $_align[] = ''; // left
+ } else if (isset($matches[3])) {
+ $_align[] = 'center';
+ } else {
+ $_align[] = 'right';
+ }
+ }
} else {
- $align[] = '';
- $value[] = $val;
+ $_value[] = $cell;
+ $_align[] = '';
}
}
- $this->col = count($value);
- $colspan = array();
- foreach ($value as $val)
- $colspan[] = ($val == '==') ? 0 : 1;
- $str = '';
- $count = count($value);
- for ($i = 0; $i < $count; $i++) {
- if ($colspan[$i]) {
- while ($i + $colspan[$i] < $count && $value[$i + $colspan[$i]] == '==')
- $colspan[$i]++;
- $colspan[$i] = ($colspan[$i] > 1) ? ' colspan="' . $colspan[$i] . '"' : '';
- $str .= '<td class="style_td"' . $align[$i] . $colspan[$i] . '>' . make_link($value[$i]) . '</td>';
- }
+
+ for ($i = 0; $i < $col; $i++) {
+ if ($_value[$i] === FALSE) continue;
+ $colspan = 1;
+ while (isset($_value[$i + $colspan]) && $_value[$i + $colspan] === FALSE) ++$colspan;
+ $colspan = ($colspan > 1) ? ' colspan="' . $colspan . '"' : '';
+ $align = $_align[$i] ? ' style="text-align:' . $_align[$i] . '"' : '';
+ $str[] = '<td class="style_td"' . $align . $colspan . '>';
+ $str[] = make_link($_value[$i]);
+ $str[] = '</td>';
+ unset($_value[$i], $_align[$i]);
}
- $this->elements[] = $str;
+
+ $this->col = $col;
+ $this->elements[] = implode('', $str);
}
function canContain(& $obj)
function toString()
{
$rows = '';
- foreach ($this->elements as $str)
+ foreach ($this->elements as $str) {
$rows .= "\n" . '<tr class="style_tr">' . $str . '</tr>' . "\n";
+ }
$rows = $this->wrap($rows, 'table', ' class="style_table" cellspacing="1" border="0"');
return $this->wrap($rows, 'div', ' class="ie5"');
}
{
function Pre(& $root, $text)
{
+ $this->__construct($root, $text);
+ }
+ function __construct(& $root, $text)
+ {
global $preformat_ltrim;
- parent::Element();
+ parent::__construct();
$this->elements[] = htmlsc(
(! $preformat_ltrim || $text == '' || $text{0} != ' ') ? $text : substr($text, 1));
}
function Div($out)
{
- parent::Element();
+ $this->__construct($out);
+ }
+ function __construct($out)
+ {
+ parent::__construct();
list(, $this->name, $this->param) = array_pad($out, 3, '');
}
function Align($align)
{
- parent::Element();
+ $this->__construct($align);
+ }
+ function __construct($align)
+ {
+ parent::__construct();
$this->align = $align;
}
function Body($id)
{
+ $this->__construct($id);
+ }
+ function __construct($id)
+ {
$this->id = $id;
- $this->contents = & new Element();
+ $this->contents = new Element();
$this->contents_last = & $this->contents;
- parent::Element();
+ parent::__construct();
}
function parse(& $lines)
{
function Contents_UList($text, $level, $id)
{
+ $this->__construct($text, $level, $id);
+ }
+ function __construct($text, $level, $id)
+ {
// Reformatting $text
// A line started with "\n" means "preformatted" ... X(
make_heading($text);
$text = "\n" . '<a href="#' . $id . '">' . $text . '</a>' . "\n";
- parent::ListContainer('ul', 'li', '-', str_repeat('-', $level));
+ parent::__construct('ul', 'li', '-', str_repeat('-', $level));
$this->insert(Factory_Inline($text));
}
function setParent(& $parent)
{
- global $_list_pad_str;
-
parent::setParent($parent);
$step = $this->level;
- $margin = $this->left_margin;
if (isset($parent->parent) && is_a($parent->parent, 'ListContainer')) {
$step -= $parent->parent->level;
- $margin = 0;
}
- $margin += $this->margin * ($step == $this->level ? 1 : $step);
- $this->style = sprintf($_list_pad_str, $this->level, $margin, $margin);
+ $indent_level = ($step == $this->level ? 1 : $step);
+ $this->style = sprintf(pkwk_list_attrs_template(), $this->level, $indent_level);
}
}
-?>