Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .php-cs-fixer.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"php":"8.4.18","version":"3.95.3:v3.95.3#3d681493acc0e93283481b1c63c263737df78687","indent":" ","lineEnding":"\n","rules":{"align_multiline_comment":{"comment_type":"phpdocs_only"},"array_indentation":true,"array_syntax":{"syntax":"short"},"binary_operator_spaces":{"default":"single_space"},"blank_line_before_statement":{"statements":["if","return","while","for","foreach","do"]},"blank_line_after_opening_tag":true,"blank_line_after_namespace":true,"full_opening_tag":true,"fully_qualified_strict_types":true,"line_ending":true,"linebreak_after_opening_tag":true,"lowercase_cast":true,"lowercase_keywords":true,"lowercase_static_reference":true,"no_alternative_syntax":true,"no_blank_lines_after_class_opening":true,"no_blank_lines_after_phpdoc":true,"no_blank_lines_before_namespace":true,"no_closing_tag":true,"no_empty_comment":true,"no_empty_phpdoc":true,"no_empty_statement":true,"no_multiline_whitespace_around_double_arrow":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_unused_imports":true,"single_import_per_statement":true,"single_blank_line_at_eof":true,"no_whitespace_in_blank_line":true,"ordered_imports":{"sort_algorithm":"alpha"},"ordered_class_elements":{"sort_algorithm":"alpha","order":["constant_public","constant_protected","constant_private","property_public","property_protected","property_private","construct","method_public","method_private"]},"no_mixed_echo_print":{"use":"echo"},"constant_case":{"case":"lower"},"increment_style":{"style":"post"},"concat_space":{"spacing":"none"},"braces":{"allow_single_line_closure":false,"position_after_functions_and_oop_constructs":"same","position_after_anonymous_constructs":"next","position_after_control_structures":"same"},"class_definition":{"single_line":true}},"ruleCustomisationPolicyVersion":"null-policy","hashes":{"WebFiori\/Ui\/ListItem.php":"ea7d937d7f0f87b387231e19f408bac4","WebFiori\/Ui\/Input.php":"a32571b47302e88abe1a1b593f05c580","WebFiori\/Ui\/Exceptions\/TemplateNotFoundException.php":"0525fa91afe1452e9e2cb3817a5d20d0","WebFiori\/Ui\/Exceptions\/InvalidNodeNameException.php":"34dcd7ac55b28f1038b910cf4b1d6294","WebFiori\/Ui\/TemplateCompiler.php":"a7729de8052c9b71d8d6eda1da60f18d","WebFiori\/Ui\/TableRow.php":"c6dfd353a53a6b1ea0fa373cabf6ac99","WebFiori\/Ui\/Br.php":"874d09a7145347cbdbac3f893272bc4e","WebFiori\/Ui\/JsCode.php":"a70c5cabef6bd72ee89a55b10f88fead","WebFiori\/Ui\/Label.php":"408765b9d4a663229900d37e95c4e11d","WebFiori\/Ui\/HTMLList.php":"bcdc411a01b7ebc745e46a36b6871162","WebFiori\/Ui\/TableCell.php":"c622079f8a69e271fbcbcdb2b8e5fbf4","WebFiori\/Ui\/HTMLTable.php":"2d3cf67e93ab3e465cc5c57efe107cce","WebFiori\/Ui\/HeadNode.php":"d6ca40f301ba32df712304ff3d43d294","WebFiori\/Ui\/RadioGroup.php":"eaa8804e05590ad82ca3d7ffd3ec48c6","WebFiori\/Ui\/HTMLNode.php":"3fbee82bf49c0982ec60c94737c8dab7","WebFiori\/Ui\/Anchor.php":"d037b740c3115c48c44d92a296c50f6b","WebFiori\/Ui\/UnorderedList.php":"7f4c6f8b415392a764b1ab116c89ad90","WebFiori\/Ui\/OrderedList.php":"ed8d4fd70121b5d6411acf0a42604c91","WebFiori\/Ui\/HTMLDoc.php":"680405abb4862b29f467211bcc83afec","WebFiori\/Ui\/CodeSnippet.php":"c4cd75c3cf5d61d065160401d8198c3b","WebFiori\/Ui\/Paragraph.php":"779c96103576311cec2b08e20c229c1a"}}
1 change: 1 addition & 0 deletions WebFiori/Ui/Anchor.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This file is licensed under MIT License.
*
Expand Down
1 change: 1 addition & 0 deletions WebFiori/Ui/Br.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This file is licensed under MIT License.
*
Expand Down
1 change: 1 addition & 0 deletions WebFiori/Ui/CodeSnippet.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This file is licensed under MIT License.
*
Expand Down
1 change: 1 addition & 0 deletions WebFiori/Ui/Exceptions/InvalidNodeNameException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This file is licensed under MIT License.
*
Expand Down
1 change: 1 addition & 0 deletions WebFiori/Ui/Exceptions/TemplateNotFoundException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This file is licensed under MIT License.
*
Expand Down
1 change: 1 addition & 0 deletions WebFiori/Ui/HTMLDoc.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This file is licensed under MIT License.
*
Expand Down
1 change: 1 addition & 0 deletions WebFiori/Ui/HTMLList.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This file is licensed under MIT License.
*
Expand Down
83 changes: 57 additions & 26 deletions WebFiori/Ui/HTMLNode.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This file is licensed under MIT License.
*
Expand Down Expand Up @@ -843,7 +844,7 @@ public static function fixBareLineFeed(string $str) : string {
if ($char == "\n") {
if ($index != 0 && $str[$index - 1] != "\r") {
//Bare line feed found. Replace with \r\n
$finalStr = trim($finalStr).HTMLDoc::NL;
$finalStr = rtrim($finalStr, "\n").HTMLDoc::NL;
} else {
$finalStr .= $char;
}
Expand Down Expand Up @@ -1160,11 +1161,29 @@ public function getStyle() : array {

if ($styleStr !== null) {
$retVal = [];
$arr1 = explode(';', trim($styleStr,';'));
$styleStr = trim($styleStr, ';');
$depth = 0;
$current = '';

for ($i = 0; $i < strlen($styleStr); $i++) {
$ch = $styleStr[$i];

if ($ch === '(') {
$depth++;
} else if ($ch === ')') {
$depth--;
}

foreach ($arr1 as $val) {
$exp = explode(':', $val);
$retVal[$exp[0]] = $exp[1];
if ($ch === ';' && $depth === 0) {
$this->parseStylePair($current, $retVal);
$current = '';
} else {
$current .= $ch;
}
}

if (trim($current) !== '') {
$this->parseStylePair($current, $retVal);
}

return $retVal;
Expand Down Expand Up @@ -1651,7 +1670,7 @@ public function open() : string {
$valType = gettype($val);
$quoted = $this->isQuotedAttribute();

if (!$quoted && $valType == "integer" || $valType == 'double') {
if (!$quoted && ($valType == "integer" || $valType == 'double')) {
$retVal .= ' '.$attr.'='.$val;
} else {
if ($val != '' && !$quoted && strpos($val, '?') === false
Expand All @@ -1661,7 +1680,7 @@ public function open() : string {
&& strpos($val, '-') === false) {
$retVal .= ' '.$attr.'='.$val;
} else {
$retVal .= ' '.$attr.'="'.str_replace('"', '\"', $val).'"';
$retVal .= ' '.$attr.'="'.str_replace(['&', '"'], ['&amp;', '&quot;'], $val).'"';
}
}
}
Expand Down Expand Up @@ -1910,15 +1929,18 @@ public function setAttribute(string $name, mixed $val = null) : HTMLNode {
} else if ($val === null) {
$this->attributes[$trimmedName] = null;
} else if ($attrValType == 'string') {
$this->attributes[$trimmedName] = $trimmedVal;
$this->attributes[$trimmedName] = $trimmedVal;
} else if (in_array($attrValType, ['double', 'integer'])) {
$this->attributes[$trimmedName] = $val;
} else if ($attrValType == 'boolean') {
$this->attributes[$trimmedName] = $val === true ? 'true' : 'false';
}
} else {
throw new \InvalidArgumentException("Invalid attribute name: '$trimmedName'.");
}
}


return $this;
}
/**
Expand Down Expand Up @@ -2494,7 +2516,6 @@ private function closeAsCode(array $FO) : string {
} else {
return '&lt;/'.$this->getNodeName().'&gt;';
}

}
/**
*
Expand Down Expand Up @@ -2640,6 +2661,32 @@ private function openAsCode(array $FO) : string {

return $retVal;
}
/**
* Validates the name of the node.
*
* @param string $name The name of the node in lower case.
*
* @return bool If the name is valid, the method will return true. If
* it is not valid, it will return false. Valid values must follow the
* following rules:
* <ul>
* <li>Must not be an empty string.</li>
* <li>Must not start with a number.</li>
* <li>Must not start with '-'.</li>
* <li>Can only have the following characters in its name: [A-Z], [a-z],
* [0-9], ':', '@' and '-'.</li>
* <ul>
*
*/
private function parseStylePair(string $pair, array &$result): void {
$colonPos = strpos($pair, ':');

if ($colonPos !== false) {
$key = trim(substr($pair, 0, $colonPos));
$val = trim(substr($pair, $colonPos + 1));
$result[$key] = $val;
}
}
private function popNode() {
$node = $this->nodesStack->pop();

Expand Down Expand Up @@ -2800,23 +2847,6 @@ private function removeChHelper($node) {
private function setParentHelper(?HTMLNode $node) {
$this->parentNode = $node;
}
/**
* Validates the name of the node.
*
* @param string $name The name of the node in lower case.
*
* @return bool If the name is valid, the method will return true. If
* it is not valid, it will return false. Valid values must follow the
* following rules:
* <ul>
* <li>Must not be an empty string.</li>
* <li>Must not start with a number.</li>
* <li>Must not start with '-'.</li>
* <li>Can only have the following characters in its name: [A-Z], [a-z],
* [0-9], ':', '@' and '-'.</li>
* <ul>
*
*/
private function validateAttrNameHelper(string $name) : bool {
$nameLen = strlen($name);

Expand Down Expand Up @@ -2882,6 +2912,7 @@ private function validateFormattingOptions(array $FO): array {
} else {
$FO['tab-spaces'] = self::DEFAULT_CODE_FORMAT['tab-spaces'];
}

//initial tab validation
if (gettype($FO['initial-tab']) == 'integer' && $FO['initial-tab'] < 0) {
$FO['initial-tab'] = 0;
Expand Down
15 changes: 9 additions & 6 deletions WebFiori/Ui/HTMLTable.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This file is licensed under MIT License.
*
Expand Down Expand Up @@ -51,10 +52,10 @@ public function __construct(int $rows, int $cols) {
'border-collapse' => 'collapse'
]);

for ($x = 0 ; $x < $this->rows() ; $x++) {
for ($x = 0 ; $x < $this->rows ; $x++) {
$row = new TableRow();

for ($y = 0 ; $y < $this->cols() ; $y++) {
for ($y = 0 ; $y < $this->cols ; $y++) {
$row->addCell('');
}
$this->addRow($row);
Expand Down Expand Up @@ -108,7 +109,9 @@ public function addRow(TableRow|array $arrOrRowObj) {
* @return int Number of columns in the table.
*/
public function cols() : int {
return $this->cols;
$firstRow = $this->getChild(0);

return $firstRow !== null ? $firstRow->childrenCount() : 0;
}
/**
* Returns a table cell given its indices.
Expand Down Expand Up @@ -204,11 +207,11 @@ public function removeCol(int $colIndex) : array {
public function removeRow(int $rowIndex) {
if ($this->rows() > 1) {
$row = $this->removeChild($rowIndex);

if ($row !== null) {
$this->rows--;
}

return $row;
}
}
Expand All @@ -218,7 +221,7 @@ public function removeRow(int $rowIndex) {
* @return int Number of rows in the table.
*/
public function rows() : int {
return $this->rows;
return $this->childrenCount();
}
/**
* Sets the attributes of cells in one specific column.
Expand Down
77 changes: 39 additions & 38 deletions WebFiori/Ui/HeadNode.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This file is licensed under MIT License.
*
Expand Down Expand Up @@ -451,43 +452,6 @@ public function addLink(string $rel, string $href, array $otherAttrs = []) : Hea

return $this;
}
public function addMetaHttpEquiv(string $name, string $content, bool $override = false) : HeadNode {
$trimmedName = trim(strtolower($name));

if (strlen($trimmedName) != 0) {
$meta = $this->getMeta($trimmedName, true);

if ($meta !== null && $override === true) {
$meta->setAttribute('content', $content);

return $this;
} else if ($meta === null) {
$meta = new HTMLNode('meta');
$meta->setAttribute('http-equiv', $trimmedName);
$meta->setAttribute('content', $content);
$this->insertMetaInCorrectOrder($meta);
}
}

return $this;
}
private function insertMetaInCorrectOrder(HTMLNode $newMeta) {
$insertPosition = -1;

for ($x = 0 ; $x < $this->childrenCount() ; $x++) {
$chNode = $this->getChild($x);

if ($chNode->getNodeName() == 'meta') {
$insertPosition = $x;
}
}

if ($insertPosition != -1) {
$this->insert($newMeta, $insertPosition + 1);
} else {
$this->addChild($newMeta);
}
}
/**
* Adds new meta tag.
*
Expand Down Expand Up @@ -525,6 +489,26 @@ public function addMeta(string $name, string $content, bool $override = false) :

return $this;
}
public function addMetaHttpEquiv(string $name, string $content, bool $override = false) : HeadNode {
$trimmedName = trim(strtolower($name));

if (strlen($trimmedName) != 0) {
$meta = $this->getMeta($trimmedName, true);

if ($meta !== null && $override === true) {
$meta->setAttribute('content', $content);

return $this;
} else if ($meta === null) {
$meta = new HTMLNode('meta');
$meta->setAttribute('http-equiv', $trimmedName);
$meta->setAttribute('content', $content);
$this->insertMetaInCorrectOrder($meta);
}
}

return $this;
}
/**
* Adds a set of meta tags.
*
Expand Down Expand Up @@ -708,7 +692,7 @@ public function getLinkNodes() : LinkedList {
public function getMeta(string $name, bool $httpEquvi = false) {
$lName = strtolower(trim($name));
$attribute = $httpEquvi ? 'http-equiv' : 'name';

if ($lName == 'charset') {
return $this->getCharsetNode();
} else {
Expand Down Expand Up @@ -1115,4 +1099,21 @@ private function cssJsInsertHelper(HTMLNode $node, $otherAttrs) {
$this->addChild($node);
}
}
private function insertMetaInCorrectOrder(HTMLNode $newMeta) {
$insertPosition = -1;

for ($x = 0 ; $x < $this->childrenCount() ; $x++) {
$chNode = $this->getChild($x);

if ($chNode->getNodeName() == 'meta') {
$insertPosition = $x;
}
}

if ($insertPosition != -1) {
$this->insert($newMeta, $insertPosition + 1);
} else {
$this->addChild($newMeta);
}
}
}
1 change: 1 addition & 0 deletions WebFiori/Ui/Input.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This file is licensed under MIT License.
*
Expand Down
1 change: 1 addition & 0 deletions WebFiori/Ui/JsCode.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This file is licensed under MIT License.
*
Expand Down
1 change: 1 addition & 0 deletions WebFiori/Ui/Label.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This file is licensed under MIT License.
*
Expand Down
1 change: 1 addition & 0 deletions WebFiori/Ui/ListItem.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This file is licensed under MIT License.
*
Expand Down
1 change: 1 addition & 0 deletions WebFiori/Ui/OrderedList.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This file is licensed under MIT License.
*
Expand Down
Loading
Loading