示例#1
0
 function TableCellEx($text, $is_template = FALSE)
 {
     global $xpwiki;
     parent::ElementEx();
     $this->style = $matches = array();
     $this->is_template = $is_template;
     if ($xpwiki->root->extended_table_format) {
         $text = $this->get_cell_style($text);
     }
     while (preg_match('/^(?:(LEFT|CENTER|RIGHT)|(BG)?COLOR\\(([#_0-9a-zA-Z]+)\\)|SIZE\\((\\d+)\\)):(.*)$/', $text, $matches)) {
         if ($matches[1]) {
             $this->style['align'] = ' align="' . strtolower($matches[1]) . '"';
             $text = $matches[5];
         } else {
             if ($matches[3]) {
                 $name = $matches[2] ? 'background-color' : 'color';
                 $color = $matches[3];
                 if (preg_match("/^#[0-9a-f]{3}\$/i", $color)) {
                     $color = preg_replace("/[0-9a-f]/i", "\$0\$0", $color);
                 }
                 $this->style[$name] = $name . ':' . _htmlspecialchars($color) . ';';
                 $text = $matches[5];
             } else {
                 if ($matches[4]) {
                     $this->style['size'] = 'font-size:' . _htmlspecialchars($matches[4]) . 'px;';
                     $text = $matches[5];
                 }
             }
         }
     }
     // Text alignment
     if (empty($this->style['align'])) {
         if ($xpwiki->root->symbol_cell_align && preg_match('/^(<|=|>)(.+)$/', rtrim($text), $matches)) {
             // Text alignment with "<" or "=" or ">".
             if ($matches[1] === '=') {
                 $this->style['align'] = ' align="center"';
             } else {
                 if ($matches[1] === '>') {
                     $this->style['align'] = ' align="right"';
                 } else {
                     if ($matches[1] === '<') {
                         $this->style['align'] = ' align="left"';
                     }
                 }
             }
             $text = $matches[2];
         } else {
             if ($xpwiki->root->space_cell_align && preg_match('/^(\\s+)?(.+?)(\\s+)?$/', $text, $matches)) {
                 // Text alignment with 1 or more spaces.
                 if ($matches[2] !== '~') {
                     if (!empty($matches[1]) && !empty($matches[3])) {
                         $this->style['align'] = ' align="center"';
                     } else {
                         if (!empty($matches[1])) {
                             $this->style['align'] = ' align="right"';
                         } else {
                             if (!empty($matches[3])) {
                                 $this->style['align'] = ' align="left"';
                             }
                         }
                     }
                     if (!empty($this->style['align'])) {
                         $text = $matches[2];
                     }
                 }
             }
         }
     }
     if ($is_template && is_numeric($text)) {
         $this->style['width'] = ' width="' . $text . '"';
     }
     if (rtrim($text) === '<' || $xpwiki->root->empty_cell_join && $text === '') {
         $this->colspan = -1;
     } else {
         if (rtrim($text) === '>') {
             $this->colspan = 0;
         } else {
             if (in_array($text, array('~', '^'))) {
                 $this->rowspan = 0;
             } else {
                 if (substr($text, 0, 1) === '~') {
                     $this->tag = 'th';
                     $text = substr($text, 1);
                 }
             }
         }
     }
     if ($is_template) {
         $this->tag = 'col';
     } else {
         if ($text == '~') {
             $this->rowspan = 0;
         } else {
             if (substr($text, 0, 1) == '~') {
                 $this->tag = 'th';
                 $text = substr($text, 1);
             }
         }
     }
     if ($text != '' && $text[0] == '#') {
         // Try using DivEx class for this $text
         $obj =& Factory_DivEx($this, $text);
         if (is_a($obj, 'ParagraphEx')) {
             $obj =& $obj->elements[0];
         }
     } else {
         $obj =& Factory_InlineEx($text);
     }
     $this->insert($obj);
 }
示例#2
0
 function TableCellEx($text, $is_template = FALSE)
 {
     parent::ElementEx();
     $this->style = $matches = array();
     $this->is_template = $is_template;
     while (preg_match('/^(?:(LEFT|CENTER|RIGHT)|(BG)?COLOR\\(([#\\w]+)\\)|SIZE\\((\\d+)\\)):(.*)$/', $text, $matches)) {
         if ($matches[1]) {
             $this->style['align'] = ' align="' . strtolower($matches[1]) . '"';
             $text = $matches[5];
         } else {
             if ($matches[3]) {
                 $name = $matches[2] ? 'background-color' : 'color';
                 $color = $matches[3];
                 if (preg_match("/^#[0-9a-f]{3}\$/i", $color)) {
                     $color = preg_replace("/[0-9a-f]/i", "\$0\$0", $color);
                 }
                 $this->style[$name] = $name . ':' . htmlspecialchars($color) . ';';
                 $text = $matches[5];
             } else {
                 if ($matches[4]) {
                     $this->style['size'] = 'font-size:' . htmlspecialchars($matches[4]) . 'px;';
                     $text = $matches[5];
                 }
             }
         }
     }
     if ($is_template && is_numeric($text)) {
         $this->style['width'] = ' width="' . $text . '"';
     }
     if ($text == '>') {
         $this->colspan = 0;
     }
     if ($is_template) {
         $this->tag = 'col';
     } else {
         if ($text == '~') {
             $this->rowspan = 0;
         } else {
             if (substr($text, 0, 1) == '~') {
                 $this->tag = 'th';
                 $text = substr($text, 1);
             }
         }
     }
     if ($text != '' && $text[0] == '#') {
         // Try using DivEx class for this $text
         $obj =& Factory_DivEx($this, $text);
         if (is_a($obj, 'ParagraphEx')) {
             $obj =& $obj->elements[0];
         }
     } else {
         if (preg_match("/^(\\s+)?.+?(\\s+)?\$/", $text, $matches)) {
             $this->hspace = isset($matches[1]) ? strlen($matches[1]) : 0;
             $this->fspace = isset($matches[2]) ? strlen($matches[2]) : 0;
         }
         $obj =& Factory_InlineEx($text);
     }
     $this->insert($obj);
 }