Not logged in. · Lost password · Register
Forum: Customising UNB Modifications and plug-ins Plug-in gallery RSS
abbc table support
elven #1
Member since Sep 2006 · 20 posts
Group memberships: Members
Show profile · Link to this post
Subject: abbc table support
file: abbctable.lib.php
  1. <?php
  2. /* licence: gplv2 */
  3.  
  4.         function myabbctablecode($code, $table_width = '*') {
  5.                 if (!preg_match('/^\d+(%|px)?$/', $table_width, $matches))
  6.                         $table_width='*';
  7.  
  8.                 $lines = explode("\n", $code);
  9.                 $rowc = 0;
  10.                 $table = array();
  11.  
  12.                 $max_num_of_cols = 0;
  13.  
  14.                 $flines = array();
  15.                 $keep = "";
  16.                 foreach ($lines as $l) {
  17.                         if (trim($l) == "")
  18.                                 continue;
  19. /*                      if ($l[-1] == '\\')
  20.                                 $keep += $l . "\n";
  21.                         else
  22.                                 $keep = $l;*/
  23.                         $keep = $l;
  24.                         $flines[] = $keep;
  25.                 }
  26.  
  27.                 foreach ($flines as $l) {
  28.                         $cols = explode("|", $l);
  29.                         $row = array();
  30.                         $colc = 0;
  31.                         foreach ($cols as $c) {
  32.                                 $c = trim($c);
  33.                                 $width = "*";
  34.                                 $span = 1;
  35.  
  36.                                 if (preg_match('/^(.*?)(?:;(\d+))?(?:=(\d+(?:%|px)?))?$/', $c, $matches)) {
  37.                                         // Only allow width definitions on the first row
  38.                                         if (count($table) == 0 && $matches[3] != "") {
  39.                                                 $width = $matches[3];
  40.                                                 if (preg_match("/^\d+$/", $width))
  41.                                                         $width .= "px";
  42.                                         }
  43.                                         if ($matches[2] != "")
  44.                                                 $span = intval($matches[2]);
  45.                                         $c = $matches[1];
  46.                                 }
  47.                                 $colc += $span;
  48.                                 $row[] = array($width, $c, $span);
  49.                         }
  50.                         if (count($table) == 0)
  51.                                 $max_num_of_cols = $colc;
  52.  
  53.                         $table[] = $row;
  54.                         $rowc++;
  55.                 }
  56.  
  57.                 $rowc = 0;
  58.                 $r = '<table style="border: 1px dashed black; width: '.$table_width.'; overflow: hidden;">';
  59.                 foreach ($table as $row) {
  60.                         $rowc++;
  61.                         $r .= '<tr>';
  62.  
  63.                         // Calculate the total row count of this row
  64.                         $total_col_this_row = 0;
  65.                         foreach ($row as $cell)
  66.                                 $total_col_this_row += $cell[2];
  67.  
  68.                         $chomp = count($row)-1;
  69.                         while ($total_col_this_row != $max_num_of_cols) {
  70.                                 // We cant chop anymore!
  71.                                 if ($chomp == 0 && $row[$chomp][2] == 1) {
  72.                                         // Raise error to user
  73.                                         return "<b>Fehler in Tabelle: Zeile ".$rowc." hat zuwenig/zuviele Spalten</b>: ".
  74.                                                 $max_num_of_cols." erwartet, ".$total_col_this_row." gefunden.";
  75.                                 }
  76.  
  77.                                 // Chomp of spans from the back
  78.                                 if ($row[$chomp][2] > 1)
  79.                                         $row[$chomp][2] -= 1;
  80.                                 else
  81.                                         $chomp -= 1;
  82.  
  83.                                 // Recalculate
  84.                                 $total_col_this_row = 0;
  85.                                 foreach ($row as $cell)
  86.                                         $total_col_this_row += $cell[2];
  87.  
  88.                         }
  89.                         foreach ($row as $cell) {
  90.                                 $width = $cell[0];
  91.                                 $content = $cell[1];
  92.                                 $span = $cell[2];
  93.                                 $vcol_this_row += $span;
  94.                                 $content = AbbcProc($content);
  95.  
  96.                                 // Hack: Remove leading <br />
  97.                                 $content = preg_replace('/\r|\n/i', '', $content, 1);
  98.  
  99.                                 $r .= '<td colspan="'.$span.'" style="border: 1px dotted grey;text-align: center; width: '.$width.';">'.$content.'</td>';
  100.                         }
  101.                         $r .= '</tr>';
  102.                 }
  103.  
  104.                 $r .= '</table>';
  105.  
  106.                 return $r;
  107.         }


file: abbctable.php

  1. <?php
  2. /* licence: gplv2 */
  3.  
  4. if (!defined('UNB_RUNNING')) die('Not a UNB environment in ' . basename(__FILE__));
  5.  
  6. // Define plug-in meta-data
  7. UnbPluginMeta('Add table support to ABBC code tags');
  8. UnbPluginMeta('Bernhard \'elven\' Stoeckner <elven@swordcoast.net>', 'author');
  9.  
  10. if (!UnbPluginEnabled()) return;
  11.  
  12. include_once(dirname(__FILE__) . '/abbctable.lib.php');
  13.  
  14.  
  15. function UnbHookAddTableABBC(&$data) {
  16.         $ABBC['Tags']['table'] = array(
  17.         'htmlopen0'  => "~''.",
  18.         'htmlcont0'  => "myabbctablecode('$1').",
  19.         'htmlclose0' => "''",
  20.         'textcont0'  => '    $1',
  21.  
  22.         'htmlopen1'  => "~''.",
  23.         'htmlcont1'  => "myabbctablecode('$2', '$1').",
  24.         'htmlclose1' => "''",
  25.         'textcont1'  => '    $2',
  26.  
  27.         'htmlblock'  => true,
  28.         'minparam'   => 0,
  29.         'maxparam'   => 1,
  30.         'openclose'  => true,
  31.         'nocase'     => true,
  32.         'nested'     => true,
  33.         'proccont'   => false,
  34.         'subset'     => ABBC_CUSTOM
  35.         );
  36. }
  37.  
  38. UnbRegisterHook('abbc.userconfig', 'UnbHookAddTableABBC');
  39.  
  40. ?>

Syntax:

[ table = width_in_sanitized_css_optional ]
heading 1=width_col_1_optional | heading 2=width_2_opt | heading 3=width_3_opt

cell 1 | cell 2 | cell 3
[ / table ]

All width definitions are in pixel (default) or %.

You can colspan cells by _prefixing_ ";n" to the width modifier:  heading 1 text;2=80%

Feedback is appreciated, of course.

Edit: Example can be seen at http://forum.silbermarken.de/thread/185
I reject your reality and substitute my own.
Avatar
Draghmar #2
Member since Dec 2006 · 63 posts
Group memberships: Members
Show profile · Link to this post
I have problems with installing/using this plugin. :(
From what i understand I have to copy code from post above, past it to new file which should be named: abbctable.lib.php and abbctable.php, and I should copy these files into plugins directory. Is that correct?
If yes then...
I have no idea how to create table with this. Maybe I just don't understand posted syntax...I tried many different variations but without success. Could someone show me some example of table? I know there is in link in post above, but there is no syntax to it and I couldn't quote it because regular users can't post there.
"I have come up with a plan so cunning you could stick a tail on it and call it a weasel."
elven #3
Member since Sep 2006 · 20 posts
Group memberships: Members
Show profile · Link to this post
Sure thing.

Above linked table is generated with:

[table]

[b]Spell on self[/b]=300px| [u]Caster Level[/u]=80px | [u]Cost in XP[/u]=80px | [u]Cost in PM[/u]=80px | [u]Anmerkungen[/u]=200px

Arcane sight | 10 | 600 | 1/3XP | Macht nur bedingt Sinn
Comprehend languages | 9 | 300 | 1/3XP | -
Ultravision | 10 | 300 | 1/3XP | Ersetzt Darkvision
Detect magic | Wird spaeter in Engine implementiert;4
See invisibility | 10 | 300 | 1/3XP | -
Tongues | 10 | 600 | 1/3XP | -

[b]Spell on others[/b]| [u]Caster Level[/u] | [u]Cost in XP[/u] | [u]Cost in PM[/u] | [u]Anmerkungen[/u]

Telepathic bond | 11 | 300 | 1/3XP | -

[b]Spell on objects or areas[/b]| [u]Caster Level[/u] | [u]Cost in XP[/u] | [u]Cost in PM[/u] | [u]Anmerkungen[/u]

Alarm | 9 | 100 | 1/3XP | -
Animate objects | Wird spaeter in Engine implementiert;4
Dancing Lights | 9 | [b]25[/b] | 5 | Nur 6 DLs pro Charakter gleichzeitig
Ghost sound | 9 | 25 | 5 | Nur 6 GSs pro Charakter gleichzeitig
Invisibility | 10 | 100 | 1/3XP | -
Mages private sanctum | 13 | 1200 | 1/3XP | -
Magic mouth | Wird spaeter in Engine implementiert;4
Phase door | 13 | 600 | 1/3XP | -
Solid fog | 12 | 600 | 1/3XP | -
Stinking cloud | 10 | 1200 | 1/3XP | -
Symbol of * | Speziell/Staffentscheidung;4
Wall of fire | 12 | 1200 | 1/3XP | -
Wall of force | 13 | 1400 | 1/3XP | -
Web | 10 | 300 | 1/3XP | -
[/table]

If you cant get it to work, dont hesitate to mail me at nospamelven@swoNOSPMrdcoast.net (remove nospam and stuff). Im not looking often into this forum.
I reject your reality and substitute my own.
kalinrow #4
Member since May 2009 · 4 posts · Location: Fell
Group memberships: Members
Show profile · Link to this post
I tried that with the latest 1.6_dev version. It seems that there are two small things to change:

  • one have to add after line 15 in abbctable.php
    1. global $ABBC;

  • one have to change the tag name, because the tag table is already used now in the ABBC shipped with the forum software. I changed it for example to simpletable, because is a really easy way to create tables, compared to the intregrated one.

Thanks for that peace of code.
This post was edited on 2009-11-10, 15:05 by kalinrow.
Avatar
madra #5
User title: pixel monkey
Member since Feb 2006 · 47 posts · Location: the intarweb
Group memberships: Members
Show profile · Link to this post
thanks. i'm going to try it now.

t'would have been nice if you'd included the files as a link tho'.  copying out of the  forum adds all the line numbers into the code  :-/
**********************
work | play | discuss
**********************
Avatar
Yves (Administrator) #6
User title: UNB developer & webmaster
Member since Jan 2004 · 3814 posts · Location: Erlangen, Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Quote by madra:
t'would have been nice if you'd included the files as a link tho'.  copying out of the  forum adds all the line numbers into the code  :-/

As a side note: You can open the "quote post" view and then copy out the code from the post editor, instead of copying the formatted code from the message view. This way you won't get any line numbers in your copy. :)
♪ ...nanananah, all in all we’re just brilliant thieves, nanananah... ♪♬
Avatar
madra #7
User title: pixel monkey
Member since Feb 2006 · 47 posts · Location: the intarweb
Group memberships: Members
Show profile · Link to this post
Quote by Yves:
...You can open the "quote post" view and then copy out the code from the post editor, instead of copying the formatted code from the message view. This way you won't get any line numbers in your copy. :)

aye.  i discovered that.



... eventually  :-D
**********************
work | play | discuss
**********************
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Go to forum
This board is powered by the Unclassified NewsBoard software, 20110527-dev, © 2003-2011 by Yves Goergen
Page created in 334.4 ms (247.1 ms) · 80 database queries in 154.5 ms
Current time: 2012-02-07, 20:21:27 (UTC +01:00)