@@ -115,17 +115,17 @@ |
||
115 | 115 | /** |
116 | 116 | * @return bool |
117 | 117 | */ |
118 | - public function isDoMakeSameDomainLinksRelative(): bool; |
|
118 | + public function isDoMakeSameDomainLinksRelative(): bool; |
|
119 | 119 | |
120 | - /** |
|
121 | - * @param bool |
|
122 | - */ |
|
120 | + /** |
|
121 | + * @param bool |
|
122 | + */ |
|
123 | 123 | public function isLocalDomainSet(): bool; |
124 | 124 | |
125 | - /** |
|
126 | - * @return string |
|
127 | - */ |
|
128 | - public function getLocalDomain(): string; |
|
125 | + /** |
|
126 | + * @return string |
|
127 | + */ |
|
128 | + public function getLocalDomain(): string; |
|
129 | 129 | |
130 | 130 | /** |
131 | 131 | * @return array |
@@ -67,8 +67,8 @@ discard block |
||
67 | 67 | $attrValue, |
68 | 68 | $attrName, |
69 | 69 | 'http', |
70 | - $attributes, |
|
71 | - $htmlMin |
|
70 | + $attributes, |
|
71 | + $htmlMin |
|
72 | 72 | ); |
73 | 73 | } |
74 | 74 | |
@@ -78,24 +78,24 @@ discard block |
||
78 | 78 | $attrName, |
79 | 79 | 'https', |
80 | 80 | $attributes, |
81 | - $htmlMin |
|
81 | + $htmlMin |
|
82 | 82 | ); |
83 | 83 | } |
84 | 84 | |
85 | 85 | if ($htmlMin->isDoMakeSameDomainLinksRelative()) { |
86 | - if (!$htmlMin->isLocalDomainSet()){ |
|
87 | - $htmlMin->setLocalDomain(); |
|
88 | - } |
|
89 | - $localDomain = $htmlMin->getLocalDomain(); |
|
90 | - if ( |
|
91 | - (($attrName === 'href') || $attrName === 'src' || $attrName === 'srcset' || $attrName === 'action') |
|
92 | - && |
|
93 | - !(isset($attributes['rel']) && $attributes['rel'] === 'external') |
|
94 | - && |
|
95 | - !(isset($attributes['target']) && $attributes['target'] === '_blank') |
|
96 | - ) { |
|
97 | - $attrValue = \preg_replace("/^((https?:)?\/\/)?{$localDomain}(?!\w)(\/?)/", '/', $attrValue); |
|
98 | - } |
|
86 | + if (!$htmlMin->isLocalDomainSet()){ |
|
87 | + $htmlMin->setLocalDomain(); |
|
88 | + } |
|
89 | + $localDomain = $htmlMin->getLocalDomain(); |
|
90 | + if ( |
|
91 | + (($attrName === 'href') || $attrName === 'src' || $attrName === 'srcset' || $attrName === 'action') |
|
92 | + && |
|
93 | + !(isset($attributes['rel']) && $attributes['rel'] === 'external') |
|
94 | + && |
|
95 | + !(isset($attributes['target']) && $attributes['target'] === '_blank') |
|
96 | + ) { |
|
97 | + $attrValue = \preg_replace("/^((https?:)?\/\/)?{$localDomain}(?!\w)(\/?)/", '/', $attrValue); |
|
98 | + } |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | if ($this->removeAttributeHelper($element->tag, $attrName, $attrValue, $attributes, $htmlMin)) { |
@@ -226,8 +226,8 @@ discard block |
||
226 | 226 | string $attrValue, |
227 | 227 | string $attrName, |
228 | 228 | string $scheme, |
229 | - array $attributes, |
|
230 | - HtmlMinInterface $htmlMin |
|
229 | + array $attributes, |
|
230 | + HtmlMinInterface $htmlMin |
|
231 | 231 | ): string { |
232 | 232 | /** @noinspection InArrayCanBeUsedInspection */ |
233 | 233 | if ( |
@@ -435,7 +435,7 @@ discard block |
||
435 | 435 | $this->doRemoveHttpsPrefixFromAttributes = $doRemoveHttpsPrefixFromAttributes; |
436 | 436 | |
437 | 437 | return $this; |
438 | - } |
|
438 | + } |
|
439 | 439 | |
440 | 440 | /** |
441 | 441 | * @param bool $keepPrefixOnExternalAttributes |
@@ -468,24 +468,24 @@ discard block |
||
468 | 468 | */ |
469 | 469 | public function setLocalDomain(string $localDomain = ''): self |
470 | 470 | { |
471 | - if ($localDomain === ''){ |
|
472 | - $this->localDomain = $_SERVER['SERVER_NAME']; |
|
473 | - }else{ |
|
474 | - $this->localDomain = rtrim(preg_replace('/(https?:)?\/\//', '', $localDomain), '/'); |
|
475 | - } |
|
471 | + if ($localDomain === ''){ |
|
472 | + $this->localDomain = $_SERVER['SERVER_NAME']; |
|
473 | + }else{ |
|
474 | + $this->localDomain = rtrim(preg_replace('/(https?:)?\/\//', '', $localDomain), '/'); |
|
475 | + } |
|
476 | 476 | |
477 | 477 | return $this; |
478 | - } |
|
478 | + } |
|
479 | 479 | |
480 | - /** |
|
481 | - * @param void |
|
482 | - * |
|
483 | - * @return $this->localDomain |
|
484 | - */ |
|
485 | - public function getLocalDomain(): string |
|
486 | - { |
|
487 | - return $this->localDomain; |
|
488 | - } |
|
480 | + /** |
|
481 | + * @param void |
|
482 | + * |
|
483 | + * @return $this->localDomain |
|
484 | + */ |
|
485 | + public function getLocalDomain(): string |
|
486 | + { |
|
487 | + return $this->localDomain; |
|
488 | + } |
|
489 | 489 | |
490 | 490 | /** |
491 | 491 | * @param bool $doRemoveOmittedHtmlTags |
@@ -704,206 +704,206 @@ discard block |
||
704 | 704 | return \in_array($tag_name, self::$optional_end_tags, true) |
705 | 705 | || |
706 | 706 | ( |
707 | - $tag_name === 'li' |
|
707 | + $tag_name === 'li' |
|
708 | 708 | && |
709 | 709 | ( |
710 | - $nextSibling === null |
|
710 | + $nextSibling === null |
|
711 | 711 | || |
712 | 712 | ( |
713 | - $nextSibling instanceof \DOMElement |
|
713 | + $nextSibling instanceof \DOMElement |
|
714 | 714 | && |
715 | 715 | $nextSibling->tagName === 'li' |
716 | - ) |
|
717 | - ) |
|
718 | - ) |
|
716 | + ) |
|
717 | + ) |
|
718 | + ) |
|
719 | 719 | || |
720 | 720 | ( |
721 | - $tag_name === 'rp' |
|
721 | + $tag_name === 'rp' |
|
722 | 722 | && |
723 | 723 | ( |
724 | - $nextSibling === null |
|
724 | + $nextSibling === null |
|
725 | 725 | || |
726 | 726 | ( |
727 | - $nextSibling instanceof \DOMElement |
|
727 | + $nextSibling instanceof \DOMElement |
|
728 | 728 | && |
729 | 729 | ( |
730 | - $nextSibling->tagName === 'rp' |
|
730 | + $nextSibling->tagName === 'rp' |
|
731 | 731 | || |
732 | 732 | $nextSibling->tagName === 'rt' |
733 | - ) |
|
734 | - ) |
|
735 | - ) |
|
736 | - ) |
|
733 | + ) |
|
734 | + ) |
|
735 | + ) |
|
736 | + ) |
|
737 | 737 | || |
738 | 738 | ( |
739 | - $tag_name === 'tr' |
|
739 | + $tag_name === 'tr' |
|
740 | 740 | && |
741 | 741 | ( |
742 | - $nextSibling === null |
|
742 | + $nextSibling === null |
|
743 | 743 | || |
744 | 744 | ( |
745 | - $nextSibling instanceof \DOMElement |
|
745 | + $nextSibling instanceof \DOMElement |
|
746 | 746 | && |
747 | 747 | $nextSibling->tagName === 'tr' |
748 | - ) |
|
749 | - ) |
|
750 | - ) |
|
748 | + ) |
|
749 | + ) |
|
750 | + ) |
|
751 | 751 | || |
752 | 752 | ( |
753 | - $tag_name === 'source' |
|
753 | + $tag_name === 'source' |
|
754 | 754 | && |
755 | 755 | ( |
756 | - $parent_tag_name === 'audio' |
|
756 | + $parent_tag_name === 'audio' |
|
757 | 757 | || |
758 | 758 | $parent_tag_name === 'video' |
759 | 759 | || |
760 | 760 | $parent_tag_name === 'picture' |
761 | 761 | || |
762 | 762 | $parent_tag_name === 'source' |
763 | - ) |
|
763 | + ) |
|
764 | 764 | && |
765 | 765 | ( |
766 | - $nextSibling === null |
|
766 | + $nextSibling === null |
|
767 | 767 | || |
768 | 768 | ( |
769 | - $nextSibling instanceof \DOMElement |
|
769 | + $nextSibling instanceof \DOMElement |
|
770 | 770 | && |
771 | 771 | $nextSibling->tagName === 'source' |
772 | - ) |
|
773 | - ) |
|
774 | - ) |
|
772 | + ) |
|
773 | + ) |
|
774 | + ) |
|
775 | 775 | || |
776 | 776 | ( |
777 | - ( |
|
778 | - $tag_name === 'td' |
|
777 | + ( |
|
778 | + $tag_name === 'td' |
|
779 | 779 | || |
780 | 780 | $tag_name === 'th' |
781 | - ) |
|
781 | + ) |
|
782 | 782 | && |
783 | 783 | ( |
784 | - $nextSibling === null |
|
784 | + $nextSibling === null |
|
785 | 785 | || |
786 | 786 | ( |
787 | - $nextSibling instanceof \DOMElement |
|
787 | + $nextSibling instanceof \DOMElement |
|
788 | 788 | && |
789 | 789 | ( |
790 | - $nextSibling->tagName === 'td' |
|
790 | + $nextSibling->tagName === 'td' |
|
791 | 791 | || |
792 | 792 | $nextSibling->tagName === 'th' |
793 | - ) |
|
794 | - ) |
|
795 | - ) |
|
796 | - ) |
|
793 | + ) |
|
794 | + ) |
|
795 | + ) |
|
796 | + ) |
|
797 | 797 | || |
798 | 798 | ( |
799 | - ( |
|
800 | - $tag_name === 'dd' |
|
799 | + ( |
|
800 | + $tag_name === 'dd' |
|
801 | 801 | || |
802 | 802 | $tag_name === 'dt' |
803 | - ) |
|
803 | + ) |
|
804 | 804 | && |
805 | 805 | ( |
806 | - ( |
|
807 | - $nextSibling === null |
|
806 | + ( |
|
807 | + $nextSibling === null |
|
808 | 808 | && |
809 | 809 | $tag_name === 'dd' |
810 | - ) |
|
810 | + ) |
|
811 | 811 | || |
812 | 812 | ( |
813 | - $nextSibling instanceof \DOMElement |
|
813 | + $nextSibling instanceof \DOMElement |
|
814 | 814 | && |
815 | 815 | ( |
816 | - $nextSibling->tagName === 'dd' |
|
816 | + $nextSibling->tagName === 'dd' |
|
817 | 817 | || |
818 | 818 | $nextSibling->tagName === 'dt' |
819 | - ) |
|
820 | - ) |
|
821 | - ) |
|
822 | - ) |
|
819 | + ) |
|
820 | + ) |
|
821 | + ) |
|
822 | + ) |
|
823 | 823 | || |
824 | 824 | ( |
825 | - $tag_name === 'option' |
|
825 | + $tag_name === 'option' |
|
826 | 826 | && |
827 | 827 | ( |
828 | - $nextSibling === null |
|
828 | + $nextSibling === null |
|
829 | 829 | || |
830 | 830 | ( |
831 | - $nextSibling instanceof \DOMElement |
|
831 | + $nextSibling instanceof \DOMElement |
|
832 | 832 | && |
833 | 833 | ( |
834 | - $nextSibling->tagName === 'option' |
|
834 | + $nextSibling->tagName === 'option' |
|
835 | 835 | || |
836 | 836 | $nextSibling->tagName === 'optgroup' |
837 | - ) |
|
838 | - ) |
|
839 | - ) |
|
840 | - ) |
|
837 | + ) |
|
838 | + ) |
|
839 | + ) |
|
840 | + ) |
|
841 | 841 | || |
842 | 842 | ( |
843 | - $tag_name === 'p' |
|
843 | + $tag_name === 'p' |
|
844 | 844 | && |
845 | 845 | ( |
846 | - ( |
|
847 | - $nextSibling === null |
|
846 | + ( |
|
847 | + $nextSibling === null |
|
848 | 848 | && |
849 | 849 | ( |
850 | - $node->parentNode !== null |
|
850 | + $node->parentNode !== null |
|
851 | 851 | && |
852 | 852 | !\in_array( |
853 | - $node->parentNode->nodeName, |
|
854 | - [ |
|
855 | - 'a', |
|
856 | - 'audio', |
|
857 | - 'del', |
|
858 | - 'ins', |
|
859 | - 'map', |
|
860 | - 'noscript', |
|
861 | - 'video', |
|
862 | - ], |
|
863 | - true |
|
864 | - ) |
|
865 | - ) |
|
866 | - ) |
|
853 | + $node->parentNode->nodeName, |
|
854 | + [ |
|
855 | + 'a', |
|
856 | + 'audio', |
|
857 | + 'del', |
|
858 | + 'ins', |
|
859 | + 'map', |
|
860 | + 'noscript', |
|
861 | + 'video', |
|
862 | + ], |
|
863 | + true |
|
864 | + ) |
|
865 | + ) |
|
866 | + ) |
|
867 | 867 | || |
868 | 868 | ( |
869 | - $nextSibling instanceof \DOMElement |
|
869 | + $nextSibling instanceof \DOMElement |
|
870 | 870 | && |
871 | 871 | \in_array( |
872 | - $nextSibling->tagName, |
|
873 | - [ |
|
874 | - 'address', |
|
875 | - 'article', |
|
876 | - 'aside', |
|
877 | - 'blockquote', |
|
878 | - 'dir', |
|
879 | - 'div', |
|
880 | - 'dl', |
|
881 | - 'fieldset', |
|
882 | - 'footer', |
|
883 | - 'form', |
|
884 | - 'h1', |
|
885 | - 'h2', |
|
886 | - 'h3', |
|
887 | - 'h4', |
|
888 | - 'h5', |
|
889 | - 'h6', |
|
890 | - 'header', |
|
891 | - 'hgroup', |
|
892 | - 'hr', |
|
893 | - 'menu', |
|
894 | - 'nav', |
|
895 | - 'ol', |
|
896 | - 'p', |
|
897 | - 'pre', |
|
898 | - 'section', |
|
899 | - 'table', |
|
900 | - 'ul', |
|
901 | - ], |
|
902 | - true |
|
903 | - ) |
|
904 | - ) |
|
905 | - ) |
|
906 | - ); |
|
872 | + $nextSibling->tagName, |
|
873 | + [ |
|
874 | + 'address', |
|
875 | + 'article', |
|
876 | + 'aside', |
|
877 | + 'blockquote', |
|
878 | + 'dir', |
|
879 | + 'div', |
|
880 | + 'dl', |
|
881 | + 'fieldset', |
|
882 | + 'footer', |
|
883 | + 'form', |
|
884 | + 'h1', |
|
885 | + 'h2', |
|
886 | + 'h3', |
|
887 | + 'h4', |
|
888 | + 'h5', |
|
889 | + 'h6', |
|
890 | + 'header', |
|
891 | + 'hgroup', |
|
892 | + 'hr', |
|
893 | + 'menu', |
|
894 | + 'nav', |
|
895 | + 'ol', |
|
896 | + 'p', |
|
897 | + 'pre', |
|
898 | + 'section', |
|
899 | + 'table', |
|
900 | + 'ul', |
|
901 | + ], |
|
902 | + true |
|
903 | + ) |
|
904 | + ) |
|
905 | + ) |
|
906 | + ); |
|
907 | 907 | } |
908 | 908 | |
909 | 909 | protected function domNodeToString(\DOMNode $node): string |
@@ -935,9 +935,9 @@ discard block |
||
935 | 935 | } |
936 | 936 | |
937 | 937 | $html .= '<!DOCTYPE ' . $child->name . '' |
938 | - . ($child->publicId ? ' ' . $tmpTypePublic . ' "' . $child->publicId . '"' : '') |
|
939 | - . ($child->systemId ? ' ' . $tmpTypeSystem . ' "' . $child->systemId . '"' : '') |
|
940 | - . '>'; |
|
938 | + . ($child->publicId ? ' ' . $tmpTypePublic . ' "' . $child->publicId . '"' : '') |
|
939 | + . ($child->systemId ? ' ' . $tmpTypeSystem . ' "' . $child->systemId . '"' : '') |
|
940 | + . '>'; |
|
941 | 941 | } |
942 | 942 | } elseif ($child instanceof \DOMElement) { |
943 | 943 | $html .= \rtrim('<' . $child->tagName . ' ' . $this->domNodeAttributesToString($child)); |
@@ -1129,14 +1129,14 @@ discard block |
||
1129 | 1129 | public function isDoMakeSameDomainLinksRelative(): bool |
1130 | 1130 | { |
1131 | 1131 | return $this->doMakeSameDomainLinksRelative; |
1132 | - } |
|
1132 | + } |
|
1133 | 1133 | |
1134 | 1134 | /** |
1135 | 1135 | * @param bool |
1136 | 1136 | */ |
1137 | 1137 | public function isLocalDomainSet(): bool |
1138 | 1138 | { |
1139 | - return (!empty($this->localDomain)); |
|
1139 | + return (!empty($this->localDomain)); |
|
1140 | 1140 | } |
1141 | 1141 | |
1142 | 1142 | /** |