Re: RichTable.php Plugin
Stefan <[email protected]> Sun, 27 Jun 2010 19:04:55 +0200
| Newsgroups | gmane.comp.web.wiki.phpwiki.talk |
|---|---|
| Message-ID | <[email protected]> |
Hello,
one more feature added and few bugs removed.
- cell and row classes can be overwritten now.
<?plugin RichTableNEW
*class=YOURCLASS, width=100%
-valign=top
|*rowspan=2
1.1
-
|*class=YOUR-CELL-CLASS
2.1
|2.2
?>
maybe it is interesting for somebody.
Stefan
Am 27.06.2010 03:57, schrieb Stefan:
> Hallo,
> you are interested in my modified RichTable.php. The following
> fixes/anhancements are established to it.
> -W3C proofed (the old plugin only shows pictures in the last cell of
> the table when a "-" (<tr>) is at the end of the plugin. This is not
> nessassary anymore and handled inside the plugin. If allready set, an
> empty row without cell is not printed anymore)
> - different styles
> - for first row (first cell till before last cell)
> - frst row last cell
> - every next row (first cell till before last cell)
> - every next row (last cell)
> This gives you the chance to make layouts for tables without outer
> border, shadows and round corners etc. It was tricky to handle colspan
> and rowspan to find out which cell is the last one in a row (maybe its
> the one from row before at rowspan ...) but now it works
>
> how does it work?
>
> The plugin
>
> <?plugin RichTableNEW
> *class=YOURCLASS, width=100%
> -valign=top
> |*rowspan=2
> 1.1
> -
> |2.1
> |2.2
> ?>
>
> The stylesheet
>
> /* YOURCLASS = class you use in your stylesheet. Here you can use the
> following styles to make round borders and shadow in firefox and
> chrome, safari:
> */
>
> table.YOURCLASS{}
> tr.YOURCLASS {
> -moz-box-shadow: 1px 1px 2px 1px #999;
> -moz-border-radius: 4px;
> -khtml-border-radius: 4px;
> -khtml-box-shadow: 1px 1px 2px 1px #999;
> -webkit-border-radius: 4px;
> box-shadow: 1px 1px 2px 1px #999;
> border-radius: 4px;
> }
>
> /* bn = border none (right top cell) */
> td.YOURCLASS-bn {
> border: none;
> }
>
> /* bt = border top (every last cell except top cell)*/
> td.YOURCLASS-bt {
> border-top: 1px #999 solid;
> }
>
> /* br = border right (every first row cell except last one */
> td.YOURCLASS-br {
> border-right: 1px #ddd solid;
> }
>
> /*brt = border right top (every missing cell) */
> td.YOURCLASS-brt {
> border-right: 1px #ddd solid;
> border-top: 1px #ddd solid;
> }
>
> You can see it work here:
> http://www.mineralienatlas.de/lexikon/index.php/Geologische%20Zeittafel
>
> Have fun
> Stefan
>
>
>
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by Sprint
> What will you do first with EVO, the first 4G phone?
> Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
>
>
> _______________________________________________
> Phpwiki-talk mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/phpwiki-talk
------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Phpwiki-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/phpwiki-talk
RichTable.php
(text/html, 5.5 KB)
<?php // -*-php-*-
rcs_id('$Id: RichTable.php,v 2.2 2010/06/24 17:44:24 Stefan Schorn Exp $');
/**
Richtable - Tabellen plugin
*/
class WikiPlugin_RichTable
extends WikiPlugin
{
function getName() {
return _("RichTable");
}
function getDescription() {
return _("Layout tables using a very rich markup style.");
}
function getDefaultArguments() {
return array();
}
function getVersion() {
return preg_replace("/[Revision: $]/", '',
"\$Revision: 1.7 $");
}
function run($dbi, $argstr, &$request, $basepage) {
global $WikiTheme;
include_once("lib/BlockParser.php");
// RichTablePlugin markup is new.
$markup = 2.0;
$lines = preg_split('/\n/', $argstr);
$table = HTML::table();
$atlas = 0;
$atlasdl = 0;
if ($lines[0][0] == '*') {
$line = substr(array_shift($lines),1);
$attrs = $this->_parse_attr($line);
foreach ($attrs as $key => $value) {
if (in_array ($key, array("id", "class", "title", "style",
"bgcolor", "frame", "rules", "border",
"cellspacing", "cellpadding",
"summary", "align", "width"))) {
if ($key == 'class') $class = $value;
$table->setAttr($key, $value);
}
}
}
$r = 0;
$c = 0;
$ownclass = 0;
$ownclasstr = 0;
$Zelle = array();
if(is_array($lines)) $lastLine = $lines[count($lines)-1];
if (!(trim($lastLine) == '-')) { $lines[] = '-';}
foreach ($lines as $line){
if (substr($line,0,1) == "-") {
$makeit = 0;
if (isset($row)) {
if (isset($cell)) {
if ($r == 1) $cmax = $c;
if (isset($class) && $class && !$ownclass) {
if ($c == $cmax) {
if ($r == 1) {
$cell->setAttr('class', $class.'-bn');
} else {
$cell->setAttr('class', $class.'-bt');
}
} else {
if ($r == 1) {
$cell->setAttr('class', $class.'-br');
} else {
$cell->setAttr('class', $class.'-brt');
}
}
}
if (isset($content)) {
// debug $cell->pushContent(TransformText('<<'.$r.'#'.$c.'>>', $markup, $basepage));
$cell->pushContent(TransformText($content, $markup, $basepage));
unset($content);
}
$row->pushContent($cell);
unset($cell);
$makeit = 1;
}
if ($makeit == 1) {
$table->pushContent($row);
unset($row);
}
}
$r++;
$row = HTML::tr();
$attrs = $this->_parse_attr(substr($line,1));
$c = 0;
$ownclasstr = 0;
foreach ($attrs as $key => $value) {
if (in_array ($key, array("id", "class", "title", "style",
"bgcolor", "align", "valign"))) {
$row->setAttr($key, $value);
if ($key == 'class' && isset($value) && $value) {
$ownclasstr = 1;
}
}
}
if (!$ownclasstr && isset($class) && $class)
$row->setAttr('class', $class);
continue;
}
if (substr($line,0,1) == "|" and isset($row)) {
if (isset($cell)) {
if ($class && !$ownclass) {
if ($r == 1) {
$cell->setAttr('class', $class.'-br');
} else {
$cell->setAttr('class', $class.'-brt');
}
}
if (isset ($content)) {
//debug $cell->pushContent(TransformText('<<'.$r.'#'.$c.'>>', $markup, $basepage));
$cell->pushContent(TransformText($content, $markup, $basepage));
unset($content);
}
$row->pushContent($cell);
}
$keyZold = $c;
$go = 1;
if (isset($Zelle[$r])) {
foreach ($Zelle[$r] as $keyZ => $valueZ) {
$diff = $keyZ - $keyZold;
$keyZold = $keyZ;
if ($diff == 1 && $go) {
$c = $c + $valueZ;
unset($Zelle[$r][$keyZ]);
} else $go = 0;
}
}
$c++;
$cell = HTML::td();
$line = substr($line, 1);
if ($line[0] == "*" ) {
$attrs = $this->_parse_attr(substr($line,1));
$colsp = 0;
$rowsp = 0;
$ownclass = 0;
foreach ($attrs as $key => $value) {
if (in_array ($key, array("id", "class", "title", "style",
"colspan", "rowspan", "width", "height",
"bgcolor", "align", "valign"))) {
if (!($atlas && $key == 'class'))
$cell->setAttr($key, $value);
if ($key == 'colspan' && is_numeric($value)) {
$colsp = $value;
}
if ($key == 'rowspan' && is_numeric($value)) {
$rowsp = $value;
}
if ($key == 'class' && isset($value) && $value) {
$ownclass = 1;
}
}
}
if (is_numeric($colsp)) {
for ($x = 1; $x < $colsp; $x++) {
$c = $c + 1;
}
$colsp = 0;
}
if (is_numeric($rowsp)) {
$endrow = $rowsp + $r;
for ($x = ($r+1); $x < $endrow; $x++) {
$Zelle[$x][$c] = 1;
}
$rowsp = 0;
}
continue;
}
}
if (isset($row) and isset($cell)) {
$line = str_replace("?\>", "?>", $line);
$line = str_replace("\~", "~", $line);
if (empty($content)) $content = '';
$content .= $line . "\n";
}
}
// $makit - no more empty rows
$makeit = 0;
if (isset($row)) {
if (isset($cell)) {
if (isset($content))
$cell->pushContent(TransformText($content));
$makeit = 1;
$row->pushContent($cell);
}
if ($makeit == 1) {
$table->pushContent($row);
unset($row);
}
}
return $table;
}
function _parse_attr($line) {
$attr_chunks = preg_split("/\s*,\s*/", strtolower($line));
$options = array();
foreach ($attr_chunks as $attr_pair) {
if (empty($attr_pair)) continue;
$key_val = preg_split("/\s*=\s*/", $attr_pair);
if (!empty($key_val[1]))
$options[trim($key_val[0])] = trim($key_val[1]);
}
return $options;
}
}
// End:
?>