ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
PhpOffice\PhpSpreadsheet\Helper\Html Class Reference
+ Collaboration diagram for PhpOffice\PhpSpreadsheet\Helper\Html:

Public Member Functions

 toRichTextObject ($html)
 Parse HTML formatting and return the resulting RichText. More...
 

Static Public Member Functions

static colourNameLookup (string $rgb)
 

Protected Member Functions

 initialise ()
 
 cleanWhitespace ()
 
 buildTextRun ()
 
 rgbToColour ($rgb)
 
 startFontTag ($tag)
 
 endFontTag ()
 
 startBoldTag ()
 
 endBoldTag ()
 
 startItalicTag ()
 
 endItalicTag ()
 
 startUnderlineTag ()
 
 endUnderlineTag ()
 
 startSubscriptTag ()
 
 endSubscriptTag ()
 
 startSuperscriptTag ()
 
 endSuperscriptTag ()
 
 startStrikethruTag ()
 
 endStrikethruTag ()
 
 breakTag ()
 
 parseTextNode (DOMText $textNode)
 
 handleCallback (DOMElement $element, $callbackTag, array $callbacks)
 
 parseElementNode (DOMElement $element)
 
 parseElements (DOMNode $element)
 

Protected Attributes

 $face
 
 $size
 
 $color
 
 $bold = false
 
 $italic = false
 
 $underline = false
 
 $superscript = false
 
 $subscript = false
 
 $strikethrough = false
 
 $startTagCallbacks
 
 $endTagCallbacks
 
 $stack = []
 
 $stringData = ''
 
 $richTextObject
 

Static Protected Attributes

static $colourMap
 

Detailed Description

Definition at line 13 of file Html.php.

Member Function Documentation

◆ breakTag()

PhpOffice\PhpSpreadsheet\Helper\Html::breakTag ( )
protected

Definition at line 787 of file Html.php.

787 : void
788 {
789 $this->stringData .= "\n";
790 }

◆ buildTextRun()

PhpOffice\PhpSpreadsheet\Helper\Html::buildTextRun ( )
protected

Definition at line 649 of file Html.php.

649 : void
650 {
652 if (trim($text) === '') {
653 return;
654 }
655
656 $richtextRun = $this->richTextObject->createTextRun($this->stringData);
657 if ($this->face) {
658 $richtextRun->getFont()->setName($this->face);
659 }
660 if ($this->size) {
661 $richtextRun->getFont()->setSize($this->size);
662 }
663 if ($this->color) {
664 $richtextRun->getFont()->setColor(new Color('ff' . $this->color));
665 }
666 if ($this->bold) {
667 $richtextRun->getFont()->setBold(true);
668 }
669 if ($this->italic) {
670 $richtextRun->getFont()->setItalic(true);
671 }
672 if ($this->underline) {
673 $richtextRun->getFont()->setUnderline(Font::UNDERLINE_SINGLE);
674 }
675 if ($this->superscript) {
676 $richtextRun->getFont()->setSuperscript(true);
677 }
678 if ($this->subscript) {
679 $richtextRun->getFont()->setSubscript(true);
680 }
681 if ($this->strikethrough) {
682 $richtextRun->getFont()->setStrikethrough(true);
683 }
684 $this->stringData = '';
685 }
if(PHP_SAPI !='cli') color
Definition: langcheck.php:120
font size
Definition: langcheck.php:162
$text
Definition: errorreport.php:18

References PhpOffice\PhpSpreadsheet\Helper\Html\$stringData, $text, color, size, and PhpOffice\PhpSpreadsheet\Style\Font\UNDERLINE_SINGLE.

Referenced by PhpOffice\PhpSpreadsheet\Helper\Html\parseTextNode().

+ Here is the caller graph for this function:

◆ cleanWhitespace()

PhpOffice\PhpSpreadsheet\Helper\Html::cleanWhitespace ( )
protected

Definition at line 635 of file Html.php.

635 : void
636 {
637 foreach ($this->richTextObject->getRichTextElements() as $key => $element) {
638 $text = $element->getText();
639 // Trim any leading spaces on the first run
640 if ($key == 0) {
641 $text = ltrim($text);
642 }
643 // Trim any spaces immediately after a line break
644 $text = preg_replace('/\n */mu', "\n", $text);
645 $element->setText($text);
646 }
647 }
$key
Definition: croninfo.php:18

References $key, and $text.

Referenced by PhpOffice\PhpSpreadsheet\Helper\Html\toRichTextObject().

+ Here is the caller graph for this function:

◆ colourNameLookup()

static PhpOffice\PhpSpreadsheet\Helper\Html::colourNameLookup ( string  $rgb)
static

Definition at line 697 of file Html.php.

697 : string
698 {
699 return self::$colourMap[$rgb] ?? '';
700 }

◆ endBoldTag()

PhpOffice\PhpSpreadsheet\Helper\Html::endBoldTag ( )
protected

Definition at line 732 of file Html.php.

732 : void
733 {
734 $this->bold = false;
735 }

◆ endFontTag()

PhpOffice\PhpSpreadsheet\Helper\Html::endFontTag ( )
protected

Definition at line 722 of file Html.php.

722 : void
723 {
724 $this->face = $this->size = $this->color = null;
725 }

References color, and size.

◆ endItalicTag()

PhpOffice\PhpSpreadsheet\Helper\Html::endItalicTag ( )
protected

Definition at line 742 of file Html.php.

742 : void
743 {
744 $this->italic = false;
745 }

◆ endStrikethruTag()

PhpOffice\PhpSpreadsheet\Helper\Html::endStrikethruTag ( )
protected

Definition at line 782 of file Html.php.

782 : void
783 {
784 $this->strikethrough = false;
785 }

◆ endSubscriptTag()

PhpOffice\PhpSpreadsheet\Helper\Html::endSubscriptTag ( )
protected

Definition at line 762 of file Html.php.

762 : void
763 {
764 $this->subscript = false;
765 }

◆ endSuperscriptTag()

PhpOffice\PhpSpreadsheet\Helper\Html::endSuperscriptTag ( )
protected

Definition at line 772 of file Html.php.

772 : void
773 {
774 $this->superscript = false;
775 }

◆ endUnderlineTag()

PhpOffice\PhpSpreadsheet\Helper\Html::endUnderlineTag ( )
protected

Definition at line 752 of file Html.php.

752 : void
753 {
754 $this->underline = false;
755 }

◆ handleCallback()

PhpOffice\PhpSpreadsheet\Helper\Html::handleCallback ( DOMElement  $element,
  $callbackTag,
array  $callbacks 
)
protected
Parameters
string$callbackTag

Definition at line 806 of file Html.php.

806 : void
807 {
808 if (isset($callbacks[$callbackTag])) {
809 $elementHandler = $callbacks[$callbackTag];
810 if (method_exists($this, $elementHandler)) {
811 call_user_func([$this, $elementHandler], $element);
812 }
813 }
814 }

Referenced by PhpOffice\PhpSpreadsheet\Helper\Html\parseElementNode().

+ Here is the caller graph for this function:

◆ initialise()

PhpOffice\PhpSpreadsheet\Helper\Html::initialise ( )
protected

Definition at line 596 of file Html.php.

596 : void
597 {
598 $this->face = $this->size = $this->color = null;
599 $this->bold = $this->italic = $this->underline = $this->superscript = $this->subscript = $this->strikethrough = false;
600
601 $this->stack = [];
602
603 $this->stringData = '';
604 }

References color, and size.

Referenced by PhpOffice\PhpSpreadsheet\Helper\Html\toRichTextObject().

+ Here is the caller graph for this function:

◆ parseElementNode()

PhpOffice\PhpSpreadsheet\Helper\Html::parseElementNode ( DOMElement  $element)
protected

Definition at line 816 of file Html.php.

816 : void
817 {
818 $callbackTag = strtolower($element->nodeName);
819 $this->stack[] = $callbackTag;
820
821 $this->handleCallback($element, $callbackTag, $this->startTagCallbacks);
822
823 $this->parseElements($element);
824 array_pop($this->stack);
825
826 $this->handleCallback($element, $callbackTag, $this->endTagCallbacks);
827 }
parseElements(DOMNode $element)
Definition: Html.php:829
handleCallback(DOMElement $element, $callbackTag, array $callbacks)
Definition: Html.php:806

References PhpOffice\PhpSpreadsheet\Helper\Html\handleCallback(), and PhpOffice\PhpSpreadsheet\Helper\Html\parseElements().

Referenced by PhpOffice\PhpSpreadsheet\Helper\Html\parseElements().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseElements()

PhpOffice\PhpSpreadsheet\Helper\Html::parseElements ( DOMNode  $element)
protected

Definition at line 829 of file Html.php.

829 : void
830 {
831 foreach ($element->childNodes as $child) {
832 if ($child instanceof DOMText) {
833 $this->parseTextNode($child);
834 } elseif ($child instanceof DOMElement) {
835 $this->parseElementNode($child);
836 }
837 }
838 }
parseTextNode(DOMText $textNode)
Definition: Html.php:792
parseElementNode(DOMElement $element)
Definition: Html.php:816

References PhpOffice\PhpSpreadsheet\Helper\Html\parseElementNode(), and PhpOffice\PhpSpreadsheet\Helper\Html\parseTextNode().

Referenced by PhpOffice\PhpSpreadsheet\Helper\Html\parseElementNode(), and PhpOffice\PhpSpreadsheet\Helper\Html\toRichTextObject().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseTextNode()

PhpOffice\PhpSpreadsheet\Helper\Html::parseTextNode ( DOMText  $textNode)
protected

Definition at line 792 of file Html.php.

792 : void
793 {
794 $domText = preg_replace(
795 '/\s+/u',
796 ' ',
797 str_replace(["\r", "\n"], ' ', $textNode->nodeValue)
798 );
799 $this->stringData .= $domText;
800 $this->buildTextRun();
801 }

References PhpOffice\PhpSpreadsheet\Helper\Html\buildTextRun().

Referenced by PhpOffice\PhpSpreadsheet\Helper\Html\parseElements().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rgbToColour()

PhpOffice\PhpSpreadsheet\Helper\Html::rgbToColour (   $rgb)
protected

Definition at line 687 of file Html.php.

688 {
689 preg_match_all('/\d+/', $rgb, $values);
690 foreach ($values[0] as &$value) {
691 $value = str_pad(dechex($value), 2, '0', STR_PAD_LEFT);
692 }
693
694 return implode('', $values[0]);
695 }
$values

References $values.

Referenced by PhpOffice\PhpSpreadsheet\Helper\Html\startFontTag().

+ Here is the caller graph for this function:

◆ startBoldTag()

PhpOffice\PhpSpreadsheet\Helper\Html::startBoldTag ( )
protected

Definition at line 727 of file Html.php.

727 : void
728 {
729 $this->bold = true;
730 }

◆ startFontTag()

PhpOffice\PhpSpreadsheet\Helper\Html::startFontTag (   $tag)
protected

Definition at line 702 of file Html.php.

702 : void
703 {
704 foreach ($tag->attributes as $attribute) {
705 $attributeName = strtolower($attribute->name);
706 $attributeValue = $attribute->value;
707
708 if ($attributeName == 'color') {
709 if (preg_match('/rgb\s*\‍(/', $attributeValue)) {
710 $this->$attributeName = $this->rgbToColour($attributeValue);
711 } elseif (strpos(trim($attributeValue), '#') === 0) {
712 $this->$attributeName = ltrim($attributeValue, '#');
713 } else {
714 $this->$attributeName = static::colourNameLookup($attributeValue);
715 }
716 } else {
717 $this->$attributeName = $attributeValue;
718 }
719 }
720 }
if(function_exists( 'posix_getuid') &&posix_getuid()===0) if(!array_key_exists('t', $options)) $tag
Definition: cron.php:35

References $tag, and PhpOffice\PhpSpreadsheet\Helper\Html\rgbToColour().

+ Here is the call graph for this function:

◆ startItalicTag()

PhpOffice\PhpSpreadsheet\Helper\Html::startItalicTag ( )
protected

Definition at line 737 of file Html.php.

737 : void
738 {
739 $this->italic = true;
740 }

◆ startStrikethruTag()

PhpOffice\PhpSpreadsheet\Helper\Html::startStrikethruTag ( )
protected

Definition at line 777 of file Html.php.

777 : void
778 {
779 $this->strikethrough = true;
780 }

◆ startSubscriptTag()

PhpOffice\PhpSpreadsheet\Helper\Html::startSubscriptTag ( )
protected

Definition at line 757 of file Html.php.

757 : void
758 {
759 $this->subscript = true;
760 }

◆ startSuperscriptTag()

PhpOffice\PhpSpreadsheet\Helper\Html::startSuperscriptTag ( )
protected

Definition at line 767 of file Html.php.

767 : void
768 {
769 $this->superscript = true;
770 }

◆ startUnderlineTag()

PhpOffice\PhpSpreadsheet\Helper\Html::startUnderlineTag ( )
protected

Definition at line 747 of file Html.php.

747 : void
748 {
749 $this->underline = true;
750 }

◆ toRichTextObject()

PhpOffice\PhpSpreadsheet\Helper\Html::toRichTextObject (   $html)

Parse HTML formatting and return the resulting RichText.

Parameters
string$html
Returns
RichText

Definition at line 613 of file Html.php.

614 {
615 $this->initialise();
616
617 // Create a new DOM object
618 $dom = new DOMDocument();
619 // Load the HTML file into the DOM object
620 // Note the use of error suppression, because typically this will be an html fragment, so not fully valid markup
621 $prefix = '<?xml encoding="UTF-8">';
622 @$dom->loadHTML($prefix . $html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
623 // Discard excess white space
624 $dom->preserveWhiteSpace = false;
625
626 $this->richTextObject = new RichText();
627 $this->parseElements($dom);
628
629 // Clean any further spurious whitespace
630 $this->cleanWhitespace();
631
633 }
$html
Definition: example_001.php:87

References $html, PhpOffice\PhpSpreadsheet\Helper\Html\$richTextObject, PhpOffice\PhpSpreadsheet\Helper\Html\cleanWhitespace(), PhpOffice\PhpSpreadsheet\Helper\Html\initialise(), and PhpOffice\PhpSpreadsheet\Helper\Html\parseElements().

+ Here is the call graph for this function:

Field Documentation

◆ $bold

PhpOffice\PhpSpreadsheet\Helper\Html::$bold = false
protected

Definition at line 541 of file Html.php.

◆ $color

PhpOffice\PhpSpreadsheet\Helper\Html::$color
protected

Definition at line 539 of file Html.php.

◆ $colourMap

PhpOffice\PhpSpreadsheet\Helper\Html::$colourMap
staticprotected

Definition at line 15 of file Html.php.

◆ $endTagCallbacks

PhpOffice\PhpSpreadsheet\Helper\Html::$endTagCallbacks
protected
Initial value:
= [
'font' => 'endFontTag',
'b' => 'endBoldTag',
'strong' => 'endBoldTag',
'i' => 'endItalicTag',
'em' => 'endItalicTag',
'u' => 'endUnderlineTag',
'ins' => 'endUnderlineTag',
'del' => 'endStrikethruTag',
'sup' => 'endSuperscriptTag',
'sub' => 'endSubscriptTag',
'br' => 'breakTag',
'p' => 'breakTag',
'h1' => 'breakTag',
'h2' => 'breakTag',
'h3' => 'breakTag',
'h4' => 'breakTag',
'h5' => 'breakTag',
'h6' => 'breakTag',
]

Definition at line 566 of file Html.php.

◆ $face

PhpOffice\PhpSpreadsheet\Helper\Html::$face
protected

Definition at line 535 of file Html.php.

◆ $italic

PhpOffice\PhpSpreadsheet\Helper\Html::$italic = false
protected

Definition at line 543 of file Html.php.

◆ $richTextObject

PhpOffice\PhpSpreadsheet\Helper\Html::$richTextObject
protected

Definition at line 594 of file Html.php.

Referenced by PhpOffice\PhpSpreadsheet\Helper\Html\toRichTextObject().

◆ $size

PhpOffice\PhpSpreadsheet\Helper\Html::$size
protected

Definition at line 537 of file Html.php.

◆ $stack

PhpOffice\PhpSpreadsheet\Helper\Html::$stack = []
protected

Definition at line 587 of file Html.php.

◆ $startTagCallbacks

PhpOffice\PhpSpreadsheet\Helper\Html::$startTagCallbacks
protected
Initial value:
= [
'font' => 'startFontTag',
'b' => 'startBoldTag',
'strong' => 'startBoldTag',
'i' => 'startItalicTag',
'em' => 'startItalicTag',
'u' => 'startUnderlineTag',
'ins' => 'startUnderlineTag',
'del' => 'startStrikethruTag',
'sup' => 'startSuperscriptTag',
'sub' => 'startSubscriptTag',
]

Definition at line 553 of file Html.php.

◆ $strikethrough

PhpOffice\PhpSpreadsheet\Helper\Html::$strikethrough = false
protected

Definition at line 551 of file Html.php.

◆ $stringData

PhpOffice\PhpSpreadsheet\Helper\Html::$stringData = ''
protected

Definition at line 589 of file Html.php.

Referenced by PhpOffice\PhpSpreadsheet\Helper\Html\buildTextRun().

◆ $subscript

PhpOffice\PhpSpreadsheet\Helper\Html::$subscript = false
protected

Definition at line 549 of file Html.php.

◆ $superscript

PhpOffice\PhpSpreadsheet\Helper\Html::$superscript = false
protected

Definition at line 547 of file Html.php.

◆ $underline

PhpOffice\PhpSpreadsheet\Helper\Html::$underline = false
protected

Definition at line 545 of file Html.php.


The documentation for this class was generated from the following file: