diff --git a/.gitattributes b/.gitattributes index 54ebcd1..ab019dd 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,4 +1,7 @@ # Files and folders here will be not included when creating package +* text eol=crlf +*.php text eol=crlf +*.html text eol=crlf /tests export-ignore /.github export-ignore /.gitignore export-ignore diff --git a/.github/workflows/php70.yml b/.github/workflows/php70.yml index f8588b9..64b0684 100644 --- a/.github/workflows/php70.yml +++ b/.github/workflows/php70.yml @@ -20,7 +20,7 @@ jobs: steps: - name: Clone Repo - uses: actions/checkout@v1 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 diff --git a/.github/workflows/php71.yml b/.github/workflows/php71.yml index 5237c9d..cce136d 100644 --- a/.github/workflows/php71.yml +++ b/.github/workflows/php71.yml @@ -20,7 +20,7 @@ jobs: steps: - name: Clone Repo - uses: actions/checkout@v1 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 diff --git a/.github/workflows/php72.yml b/.github/workflows/php72.yml index 0b963cc..22b1910 100644 --- a/.github/workflows/php72.yml +++ b/.github/workflows/php72.yml @@ -20,7 +20,7 @@ jobs: steps: - name: Clone Repo - uses: actions/checkout@v1 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 diff --git a/.github/workflows/php73.yml b/.github/workflows/php73.yml index 25b564f..647e46b 100644 --- a/.github/workflows/php73.yml +++ b/.github/workflows/php73.yml @@ -20,7 +20,7 @@ jobs: steps: - name: Clone Repo - uses: actions/checkout@v1 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 diff --git a/.github/workflows/php74.yml b/.github/workflows/php74.yml index b512a9a..0d719c9 100644 --- a/.github/workflows/php74.yml +++ b/.github/workflows/php74.yml @@ -20,7 +20,7 @@ jobs: steps: - name: Clone Repo - uses: actions/checkout@v1 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 diff --git a/.github/workflows/php80.yml b/.github/workflows/php80.yml index 678d936..224ed55 100644 --- a/.github/workflows/php80.yml +++ b/.github/workflows/php80.yml @@ -19,7 +19,7 @@ jobs: steps: - name: Clone Repo - uses: actions/checkout@v1 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 diff --git a/.github/workflows/php81.yml b/.github/workflows/php81.yml index 5a8b65d..56afd6b 100644 --- a/.github/workflows/php81.yml +++ b/.github/workflows/php81.yml @@ -20,7 +20,7 @@ jobs: steps: - name: Clone Repo - uses: actions/checkout@v1 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 diff --git a/.github/workflows/php82.yml b/.github/workflows/php82.yml index 65d2985..f965a41 100644 --- a/.github/workflows/php82.yml +++ b/.github/workflows/php82.yml @@ -20,7 +20,7 @@ jobs: steps: - name: Clone Repo - uses: actions/checkout@v1 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 diff --git a/tests/test-templates/php-template-2.php b/tests/test-templates/php-template-2.php index a4cf569..495089c 100644 --- a/tests/test-templates/php-template-2.php +++ b/tests/test-templates/php-template-2.php @@ -11,7 +11,7 @@ diff --git a/tests/webfiori/test/ui/HTMLTableTest.php b/tests/webfiori/test/ui/HTMLTableTest.php index 5abc23b..cc428df 100644 --- a/tests/webfiori/test/ui/HTMLTableTest.php +++ b/tests/webfiori/test/ui/HTMLTableTest.php @@ -29,6 +29,16 @@ public function test00() { . '' . '' . '', $table->toHTML()); + $table->setFirstColCellType('th'); + $this->assertEquals('' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '
', $table->toHTML()); $table->setIsQuotedAttribute(false); } /** diff --git a/tests/webfiori/test/ui/LoadTemplateTest.php b/tests/webfiori/test/ui/LoadTemplateTest.php index 8f3fa15..1bb25fa 100644 --- a/tests/webfiori/test/ui/LoadTemplateTest.php +++ b/tests/webfiori/test/ui/LoadTemplateTest.php @@ -83,7 +83,8 @@ public function test04() { public function test05() { $compiler = new TemplateCompiler(self::TEST_TEMPLATES_PATH.'php-template.php'); $node = $compiler->getCompiled(); - $this->assertEquals("
\n This is a test on php
", $node->toHTML()); + $this->assertEquals("
\r\n" + . " This is a test on php
", $node->toHTML()); } /** * @test @@ -111,8 +112,11 @@ public function test07() { 'posts' => [] ]); $node = $compiler->getCompiled(); - $this->assertEquals("
\n No posts.\n
", $node->toHTML()); + $this->assertEquals("
\r\n" + . " No posts.\r\n" + . "
", $node->toHTML()); } + /** * @test */ @@ -130,11 +134,51 @@ public function test08() { . "
  • Two
  • " . "
  • Three
  • " . "" - . "
    \n" + . "
    \r\n" . " Good Job!" . "
    " . "
    ", $compiler->getCompiled()->toHTML()); } + /** + * @test + */ + public function test09() { + $compiler = new TemplateCompiler('template.html'); + $this->assertEquals("
    = 8 || someVar === 6\">\r\n" + . " \r\n" + . "
    \r\n", $compiler->getCompiled()->toHTML(true)); + } + /** + * @test + */ + public function test10() { + $compiler = new TemplateCompiler('template2.php'); + $this->assertEquals("
    = 8 || someVar === 6\">\r\n" + . " \r\n" + . "
    \r\n", $compiler->getCompiled()->toHTML(true)); + } /** * @test */ diff --git a/tests/webfiori/test/ui/template.html b/tests/webfiori/test/ui/template.html new file mode 100644 index 0000000..4aebd1f --- /dev/null +++ b/tests/webfiori/test/ui/template.html @@ -0,0 +1,12 @@ +
    + +
    \ No newline at end of file diff --git a/tests/webfiori/test/ui/template2.php b/tests/webfiori/test/ui/template2.php new file mode 100644 index 0000000..896362d --- /dev/null +++ b/tests/webfiori/test/ui/template2.php @@ -0,0 +1,14 @@ + +
    + +
    \ No newline at end of file diff --git a/webfiori/ui/HTMLList.php b/webfiori/ui/HTMLList.php index 16ed9dd..6640931 100644 --- a/webfiori/ui/HTMLList.php +++ b/webfiori/ui/HTMLList.php @@ -78,7 +78,7 @@ public function addChild($node, $attrsOrChain = [], bool $chainOnParent = false) if ($node instanceof HTMLNode) { $li->addChild($node); } else { - $li->text($node); + $li->text($node.''); } return parent::addChild($li, $attrsOrChain, $chainOnParent); @@ -110,7 +110,7 @@ public function addListItem($listItemBody, bool $escHtmlEntities = true) : HTMLL if ($listItemBody instanceof HTMLNode) { $li->addChild($listItemBody); } else { - $li->text($listItemBody,$escHtmlEntities); + $li->text($listItemBody.'',$escHtmlEntities); } $this->addChild($li); } diff --git a/webfiori/ui/HTMLNode.php b/webfiori/ui/HTMLNode.php index 124846e..e586353 100644 --- a/webfiori/ui/HTMLNode.php +++ b/webfiori/ui/HTMLNode.php @@ -134,6 +134,7 @@ class HTMLNode implements Countable, Iterator { * */ private $htmlString; + private $isEsc; private static $IsFormatted = false; /** * A global static variable to decide if attributes values @@ -153,7 +154,6 @@ class HTMLNode implements Countable, Iterator { * */ private $isVoid; - private $isEsc; /** * The name of the tag (such as 'div') * @var string @@ -246,6 +246,7 @@ public function __construct(string $name = 'div', array $attrs = []) { if ($nameUpper == self::TEXT_NODE || $nameUpper == self::COMMENT_NODE) { $this->name = $nameUpper; + if ($nameUpper == self::COMMENT_NODE) { $this->isEsc = false; } @@ -1061,19 +1062,6 @@ public function getName() { public function getNodeName() : string { return $this->name; } - /** - * Sets the value of the property which is used to check if the text - * on the body of the node will be escaped or not if it has HTML entities. - * - * This only applies to text node. - * - * @param bool $esc - */ - public function setEscapeEntities(bool $esc) { - if ($this->isTextNode()) { - $this->isEsc = $esc; - } - } /** * Returns the parent node. * @@ -1782,7 +1770,7 @@ public function section($title, int $headingLvl = 1, array $attributes = []) : H if ($title instanceof HTMLNode) { $heading->addChild($title); } else { - $heading->text($title, false); + $heading->text($title.'', false); } $section = new HTMLNode('section', $attributes); $section->addChild($heading); @@ -1890,6 +1878,19 @@ public function setClassName(string $val, bool $override = true) : HTMLNode { return $this; } + /** + * Sets the value of the property which is used to check if the text + * on the body of the node will be escaped or not if it has HTML entities. + * + * This only applies to text node. + * + * @param bool $esc + */ + public function setEscapeEntities(bool $esc) { + if ($this->isTextNode()) { + $this->isEsc = $esc; + } + } /** * Sets the value of the attribute 'id' of the node. * @@ -1975,9 +1976,11 @@ public function setNodeName(string $name) : bool { if (($this->isTextNode() && $uName == self::COMMENT_NODE) || ($this->isComment() && $uName == self::TEXT_NODE)) { $this->name = $uName; + if ($uName == self::COMMENT_NODE) { $this->isEsc = false; } + return true; } else { return false; @@ -2095,9 +2098,6 @@ public function setTabIndex(int $val) : HTMLNode { */ public function setText(string $text, bool $escHtmlEntities = true) : HTMLNode { if ($this->isTextNode() || $this->isComment()) { - - - if ($this->isComment()) { $text = str_replace('', '-- ', $text)); } else { diff --git a/webfiori/ui/HTMLTable.php b/webfiori/ui/HTMLTable.php index 9b3921c..97b6e81 100644 --- a/webfiori/ui/HTMLTable.php +++ b/webfiori/ui/HTMLTable.php @@ -16,7 +16,6 @@ * * @author Ibrahim * - * @since 1.0.1 */ class HTMLTable extends HTMLNode { /** @@ -42,7 +41,6 @@ class HTMLTable extends HTMLNode { * @param int $cols Number of columns in the table. Must be greater than 0. * If less than 0 is given, the value is set to 1. * - * @since 1.0 */ public function __construct(int $rows, int $cols) { parent::__construct('table', ['border' => '1']); @@ -69,8 +67,6 @@ public function __construct(int $rows, int $cols) { * elements than the number of rows in the table, the extra rows will be * stripped off. If the array has fewer items than number of rows, the * method will fill remaining rows with empty cells. - * - * @since 1.0 */ public function addColumn(array $data = []) { for ($x = 0 ; $x < $this->rows() ; $x++) { @@ -89,8 +85,6 @@ public function addColumn(array $data = []) { * has more elements than the number of columns, the extra columns will be * stripped off. If the array has fewer elements than number of columns, the * method will add empty cells for remaining places. - * - * @since 1.0 */ public function addRow($arrOrRowObj) { if ($arrOrRowObj instanceof TableRow) { @@ -112,8 +106,6 @@ public function addRow($arrOrRowObj) { * Returns number of columns in the table. * * @return int Number of columns in the table. - * - * @since 1.0 */ public function cols() : int { return $this->cols; @@ -127,8 +119,6 @@ public function cols() : int { * * @return TableCell|null If a cell at given location exist, it is returned as * an object. Other than that, the method will return null. - * - * @since 1.0.1 */ public function getCell(int $rowIndex, int $colIndex) { $row = $this->getRow($rowIndex); @@ -144,8 +134,6 @@ public function getCell(int $rowIndex, int $colIndex) { * * @return TableRow|null If the row exist, the method will return it as an * object. If not exist, the method will return null. - * - * @since 1.0 */ public function getRow(int $rowIndex) { return $this->getChild($rowIndex); @@ -161,8 +149,6 @@ public function getRow(int $rowIndex) { * return a string that represent the value. If the cell contains HTML * element, it is returned as an object. If cell does not exist, the method * will return null. - * - * @since 1.0 */ public function getValue(int $rowIndex, int $colIndex) { $row = $this->getRow($rowIndex); @@ -189,8 +175,6 @@ public function getValue(int $rowIndex, int $colIndex) { * @return array The method will return an array that holds objects that * represents the cells of the column. If no column was removed, the array * will be empty. - * - * @since 1.0.2 */ public function removeCol(int $colIndex) : array { $colCells = []; @@ -211,8 +195,6 @@ public function removeCol(int $colIndex) : array { * @return TableRow|null If the row is removed, the method will return * an object that represents the removed row. Other than that, the method * will return null. - * - * @since 1.0.2 */ public function removeRow(int $rowIndex) { return $this->removeChild($rowIndex); @@ -221,8 +203,6 @@ public function removeRow(int $rowIndex) { * Returns number of rows in the table. * * @return int Number of rows in the table. - * - * @since 1.0 */ public function rows() : int { return $this->rows; @@ -245,9 +225,23 @@ public function setColAttributes(int $colNum, array $attributes) : HTMLTable { for ($x = 0 ; $x < $this->rows() ; $x++) { $this->getCell($x, $colNum)->setAttributes($attributes); } - + return $this; } + /** + * Update the type of cells used in first row of the table. + * + * @param string $type This can have two values, 'th' or 'td'. + */ + public function setFirstColCellType(string $type) { + $lower = strtolower(trim($type)); + + if ($type == 'td' || $type == 'th') { + for ($x = 0 ; $x < $this->cols() ; $x++) { + $this->getCell(0, $x)->setNodeName($lower); + } + } + } /** * Sets the attributes of cells in one specific row. * @@ -268,7 +262,7 @@ public function setRowAttributes(int $rowNum, array $attributes) : HTMLTable { foreach ($row->children() as $cell) { $cell->setAttributes($attributes); } - + return $this; } /** @@ -285,8 +279,6 @@ public function setRowAttributes(int $rowNum, array $attributes) : HTMLTable { * * @return HTMLTable the method will return the same instance at which the * method is called on. - * - * @since 1.0 */ public function setValue(int $rowIndex, int $colIndex, $value) : HTMLTable { if ($rowIndex < $this->rows() && $rowIndex >= 0) { @@ -298,7 +290,7 @@ public function setValue(int $rowIndex, int $colIndex, $value) : HTMLTable { if ($value instanceof HTMLNode) { $cell->addChild($value); } else { - $cell->text($value); + $cell->text($value.''); } } diff --git a/webfiori/ui/TemplateCompiler.php b/webfiori/ui/TemplateCompiler.php index 9fcc1e1..2ffcb40 100644 --- a/webfiori/ui/TemplateCompiler.php +++ b/webfiori/ui/TemplateCompiler.php @@ -762,10 +762,12 @@ private static function parseAttributesHelper(Queue $queue, bool $isEqualFound, * with the hashes. */ private static function replaceAttrsValues(string $htmlStr) : array { + $scripts = []; + preg_match_all("/(?<=