From 1ac11109e25558ba1b47cd69244294f40785b68d Mon Sep 17 00:00:00 2001 From: Adam Buckley Date: Wed, 17 Jan 2024 13:12:22 +1100 Subject: [PATCH] Merge develop into master (#229) - Inslight updates - New designs - Moved admin module to new designs - Numerous fixes --- .github/pull_request_template.md | 2 +- .github/workflows/ci.yml | 98 +- system/classes/HtmlBootstrap5.php | 53 +- .../components/CmfiveStyleComponent.php | 170 +- .../classes/html/cmfive/CodeMirrorEditor.php | 63 + system/classes/html/form.php | 18 +- system/classes/html/form/Banner.php | 99 + system/classes/html/form/Line.php | 93 + .../html/form/inputfield/DatetimeLocal.php | 4 +- system/config.php | 2 + system/functions.php | 2 +- system/html.php | 16 +- system/modules/admin/actions/editlookup.php | 34 +- system/modules/admin/actions/editprinter.php | 2 +- system/modules/admin/actions/groupadd.php | 21 +- system/modules/admin/actions/groupdelete.php | 4 +- system/modules/admin/actions/groupedit.php | 25 +- system/modules/admin/actions/groupmember.php | 10 +- system/modules/admin/actions/groups.php | 72 +- system/modules/admin/actions/index.php | 2 + system/modules/admin/actions/lookup.php | 87 +- .../admin/actions/maintenance/index.php | 2 + system/modules/admin/actions/memberdelete.php | 4 +- .../admin/actions/migration/create.php | 48 +- .../admin/actions/migration/createseed.php | 62 +- .../modules/admin/actions/migration/index.php | 2 + system/modules/admin/actions/moreInfo.php | 66 +- system/modules/admin/actions/newlookup.php | 2 +- .../modules/admin/actions/permissionedit.php | 7 +- system/modules/admin/actions/printers.php | 6 +- system/modules/admin/actions/printqueue.php | 10 +- .../modules/admin/actions/templates/edit.php | 77 +- .../modules/admin/actions/templates/index.php | 6 +- system/modules/admin/actions/user/edit.php | 155 +- system/modules/admin/actions/user/remove.php | 2 + system/modules/admin/actions/useradd.php | 84 +- system/modules/admin/actions/users.php | 157 +- system/modules/admin/models/AuditInsight.php | 18 +- system/modules/admin/models/Migration.php | 3 +- .../modules/admin/models/MigrationService.php | 4 +- system/modules/admin/templates/groups.tpl.php | 10 + system/modules/admin/templates/lookup.tpl.php | 18 +- .../admin/templates/maintenance/index.tpl.php | 138 +- .../admin/templates/migration/index.tpl.php | 492 +- .../admin/templates/permissionedit.tpl.php | 11 +- .../modules/admin/templates/printers.tpl.php | 4 +- .../admin/templates/templates/edit.tpl.php | 53 +- .../admin/templates/templates/index.tpl.php | 2 +- .../modules/admin/templates/user/edit.tpl.php | 337 +- .../admin/templates/user/remove.tpl.php | 4 +- system/modules/admin/templates/users.tpl.php | 6 +- .../tests/acceptance/AdminModuleCest.php | 2 +- .../admin/tests/acceptance/LookupCest.php | 20 +- .../admin/tests/acceptance/UserCest.php | 10 +- .../admin/tests/acceptance/UserFilterCest.php | 112 + .../acceptance/helpers/CmfiveAdminModule.php | 68 +- .../tests/acceptance/playwright/admin.test.ts | 185 + .../acceptance/playwright/admin.utils.ts | 297 + .../tests/acceptance/playwright/tsconfig.json | 21 + system/modules/auth/models/AuthService.php | 52 +- system/modules/auth/models/Contact.php | 2 +- .../modules/channels/actions/email/edit.php | 3 +- system/modules/channels/actions/index.php | 1 + .../modules/channels/actions/listchannels.php | 1 + .../modules/channels/actions/listmessages.php | 1 + .../channels/actions/listmessagestatuses.php | 1 + .../channels/actions/listprocessors.php | 1 + .../channels/actions/processor/edit.php | 2 +- .../actions/processor/editsettings.php | 2 +- system/modules/channels/actions/web/edit.php | 3 +- .../channels/templates/email/edit.tpl.php | 25 - .../channels/templates/listchannels.tpl.php | 25 +- .../channels/templates/listprocessors.tpl.php | 18 +- .../channels/templates/web/edit.tpl.php | 25 - .../acceptance/playwright/channels.test.ts | 91 + .../acceptance/playwright/channels.utils.ts | 338 + .../tests/acceptance/playwright/tsconfig.json | 21 + .../partials/actions/display_favorites.php | 3 +- system/modules/file/actions/admin/index.php | 2 + .../file/actions/admin/moveToAdapter.php | 24 +- system/modules/file/actions/deletedfiles.php | 5 +- system/modules/file/actions/edit.php | 1 + system/modules/file/models/Attachment.php | 4 +- .../file/partials/actions/attachment_item.php | 1 + .../file/partials/actions/listattachments.php | 1 + .../templates/attachment_item.tpl.php | 2 +- .../file/templates/admin/index.tpl.php | 32 +- .../file/templates/deletedfiles.tpl.php | 28 +- system/modules/file/templates/edit.tpl.php | 3 +- .../tests/acceptance/playwright/form.test.ts | 100 + .../tests/acceptance/playwright/form.utils.ts | 97 + .../tests/acceptance/playwright/tsconfig.json | 21 + system/modules/help/actions/view.php | 184 +- .../insights/actions/export/bindpdf.php | 41 +- system/modules/insights/actions/index.php | 38 +- .../insights/actions/manageMembers.php | 13 +- .../actions/members/deleteMembers.php | 2 +- .../insights/actions/members/editMembers.php | 33 +- .../modules/insights/actions/runInsight.php | 1 + .../modules/insights/actions/viewInsight.php | 5 +- .../insights/templates/export/bindpdf.tpl.php | 7 - .../insights/templates/manageMembers.tpl.php | 4 +- .../insights/templates/runInsight.tpl.php | 6 +- system/modules/main/models/CurlService.php | 30 + system/modules/report/actions/edit.php | 2 +- system/modules/report/actions/runreport.php | 2 +- .../acceptance/playwright/report.test.ts | 106 + .../acceptance/playwright/report.utils.ts | 0 .../tests/acceptance/playwright/tsconfig.json | 21 + system/modules/search/actions/index.php | 7 +- system/modules/search/actions/reindexpage.php | 3 + .../search/templates/reindexpage.tpl.php | 2 +- .../tests/acceptance/playwright/tag.test.ts | 69 + .../tests/acceptance/playwright/tag.utils.ts | 27 + .../tests/acceptance/playwright/tsconfig.json | 21 + .../modules/task/models/MyTaskTimeInsight.php | 14 +- .../tests/acceptance/playwright/task.test.ts | 93 + .../tests/acceptance/playwright/task.utils.ts | 209 + .../tests/acceptance/playwright/tsconfig.json | 21 + .../acceptance/playwright/timelog.test.ts | 59 + .../acceptance/playwright/timelog.utils.ts | 91 + .../tests/acceptance/playwright/tsconfig.json | 21 + system/modules/tokens/config.php | 10 + .../tokens/models/ApiOutputService.php | 101 + system/modules/tokens/models/TokensPolicy.php | 93 + .../modules/tokens/models/TokensService.php | 65 + system/modules/tokens/tokens.hooks.php | 37 + system/modules/tokens/tokens.roles.php | 15 + system/templates/base/.gitignore | 2 +- system/templates/base/package-lock.json | 18947 ++++------------ system/templates/base/package.json | 48 +- .../base/src/js/adaptations/table.ts | 8 +- system/templates/base/src/js/app.ts | 3 +- .../base/src/js/components/CodeMirror.ts | 47 + .../templates/base/src/js/components/index.ts | 3 +- system/templates/base/src/scss/app.scss | 15 +- .../base/src/scss/cmfive/_buttons.scss | 10 + .../base/src/scss/cmfive/_listgroup.scss | 11 + .../templates/base/src/scss/cmfive/_menu.scss | 1 + .../base/src/scss/cmfive/_mixins.scss | 11 + .../scss/cmfive/_red_squiggly_underline.scss | 7 + .../base/src/scss/cmfive/_tables.scss | 1 - .../src/scss/cmfive/adaptations/_grid.scss | 7 +- .../src/scss/cmfive/adaptations/_tables.scss | 40 +- system/templates/base/webpack.mix.js | 34 +- system/web.php | 2 +- 146 files changed, 8997 insertions(+), 15971 deletions(-) create mode 100644 system/classes/html/cmfive/CodeMirrorEditor.php create mode 100644 system/classes/html/form/Banner.php create mode 100644 system/classes/html/form/Line.php create mode 100644 system/modules/admin/templates/groups.tpl.php create mode 100644 system/modules/admin/tests/acceptance/UserFilterCest.php create mode 100644 system/modules/admin/tests/acceptance/playwright/admin.test.ts create mode 100644 system/modules/admin/tests/acceptance/playwright/admin.utils.ts create mode 100644 system/modules/admin/tests/acceptance/playwright/tsconfig.json create mode 100644 system/modules/channels/tests/acceptance/playwright/channels.test.ts create mode 100644 system/modules/channels/tests/acceptance/playwright/channels.utils.ts create mode 100644 system/modules/channels/tests/acceptance/playwright/tsconfig.json create mode 100644 system/modules/form/tests/acceptance/playwright/form.test.ts create mode 100644 system/modules/form/tests/acceptance/playwright/form.utils.ts create mode 100644 system/modules/form/tests/acceptance/playwright/tsconfig.json delete mode 100644 system/modules/insights/templates/export/bindpdf.tpl.php create mode 100644 system/modules/report/tests/acceptance/playwright/report.test.ts create mode 100644 system/modules/report/tests/acceptance/playwright/report.utils.ts create mode 100644 system/modules/report/tests/acceptance/playwright/tsconfig.json create mode 100644 system/modules/tag/tests/acceptance/playwright/tag.test.ts create mode 100644 system/modules/tag/tests/acceptance/playwright/tag.utils.ts create mode 100644 system/modules/tag/tests/acceptance/playwright/tsconfig.json create mode 100644 system/modules/task/tests/acceptance/playwright/task.test.ts create mode 100644 system/modules/task/tests/acceptance/playwright/task.utils.ts create mode 100644 system/modules/task/tests/acceptance/playwright/tsconfig.json create mode 100644 system/modules/timelog/tests/acceptance/playwright/timelog.test.ts create mode 100644 system/modules/timelog/tests/acceptance/playwright/timelog.utils.ts create mode 100644 system/modules/timelog/tests/acceptance/playwright/tsconfig.json create mode 100644 system/modules/tokens/config.php create mode 100644 system/modules/tokens/models/ApiOutputService.php create mode 100644 system/modules/tokens/models/TokensPolicy.php create mode 100644 system/modules/tokens/models/TokensService.php create mode 100644 system/modules/tokens/tokens.hooks.php create mode 100644 system/modules/tokens/tokens.roles.php create mode 100644 system/templates/base/src/js/components/CodeMirror.ts create mode 100644 system/templates/base/src/scss/cmfive/_listgroup.scss create mode 100644 system/templates/base/src/scss/cmfive/_red_squiggly_underline.scss diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 4a73144cf..4c9db9a58 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,6 +1,6 @@ ## Checklist -- [ ] I'm using the correct PHP Version (7.4 for current, 7.2 for legacy). +- [ ] I'm using the correct PHP Version (8.1 for current, 7.4 for legacy). - [ ] I've added comments to any new methods I've created or where else relevant. - [ ] I've replaced magic method usage on DbService classes with the getInstance() static method. - [ ] I've written any documentation for new features or where else relevant in the docs [repo](https://github.com/2pisoftware/cmfive-docs). diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4afa9d8d5..836a6af24 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,6 +15,7 @@ env: DB_USERNAME: cmfive_test DB_PASSWORD: cmfive_test DB_DATABASE: cmfive_test + PLAYWRIGHT_MODULES: "admin channel form tag report task timelog" jobs: # Lint @@ -58,7 +59,7 @@ jobs: - uses: actions/checkout@v3 with: repository: '2pisoftware/cmfive-boilerplate' - ref: 'master' + ref: 'develop' # Pre-requisites Prepare Cmfive Environment - name: Setup cmfive Test Environment @@ -107,7 +108,7 @@ jobs: # Build new layout - uses: actions/setup-node@v3 with: - node-version: 14 + node-version: 18 - name: Build new designs run: | @@ -123,59 +124,84 @@ jobs: if [ $? -gt 0 ]; then echo "Admin module tests failed" fi - + # Setup playwright + - name: Setup Playwright + run: | + cd test/playwright + npm ci + npx playwright install --with-deps # Run Acceptance Tests - name: "Confirm Codeception setup" run: | docker exec nginx-php8.1 bash -c "ls -lah -R /var/www/html/test/Codeception/tests && cat /var/www/html/test/Codeception/*.yml && cat /var/www/html/test/Codeception/tests/*.yml" + + # - name: "Run Playwright Module Tests" + # run: | + # export DB_HOST=mysql-8 DB_USERNAME=cmfive_test DB_PASSWORD=cmfive_test DB_DATABASE=cmfive_test DB_PORT=3306 + # sudo chmod 777 -R system/modules/admin/install/migrations/ + # cd test/playwright + + # for module in $PLAYWRIGHT_MODULES; do + # npm run test:with-retries --module="$module" --platform="chromium" --attempts=3 --reporter="github" + # done + - name: "Run admin module tests" run: | - docker exec nginx-php8.1 bash -c "DB_HOST=mysql-8 DB_USERNAME=cmfive_test DB_PASSWORD=cmfive_test DB_DATABASE=cmfive_test DB_PORT=3306 php cmfive.php tests module admin silent; exit \$?" - if [ $? -gt 0 ]; then - echo "Admin module tests failed" - fi - - name: "Run channels module tests" + sudo chmod 777 -R system/modules/admin/install/migrations/ + cd test/playwright + npm run build + npm run test --module="admin" --reporter="github" + if [ $? -gt 0 ]; then + echo "Admin module tests failed" + fi + - name: "Run channel module tests" run: | - docker exec nginx-php8.1 bash -c "DB_HOST=mysql-8 DB_USERNAME=cmfive_test DB_PASSWORD=cmfive_test DB_DATABASE=cmfive_test DB_PORT=3306 php cmfive.php tests module channels silent; exit \$?" - if [ $? -gt 0 ]; then - echo "Channels module tests failed" - fi + cd test/playwright + npm run build + npm run test --module="channel" --reporter="github" + if [ $? -gt 0 ]; then + echo "Channel module tests failed" + fi - name: "Run form module tests" run: | - docker exec nginx-php8.1 bash -c "DB_HOST=mysql-8 DB_USERNAME=cmfive_test DB_PASSWORD=cmfive_test DB_DATABASE=cmfive_test DB_PORT=3306 php cmfive.php tests module form silent; exit \$?" - if [ $? -gt 0 ]; then - echo "Form module tests failed" - fi - # - name: "Run inbox module tests" - # run: | - # docker exec nginx-php8.1 bash -c "DB_HOST=mysql-8 DB_USERNAME=cmfive_test DB_PASSWORD=cmfive_test DB_DATABASE=cmfive_test DB_PORT=3306 php cmfive.php tests module inbox silent; exit \$?" - # if [ $? -gt 0 ]; then - # echo "Inbox module tests failed" - # fi + cd test/playwright + npm run build + npm run test --module="form" --reporter="github" + if [ $? -gt 0 ]; then + echo "Form module tests failed" + fi - name: "Run report module tests" run: | - docker exec nginx-php8.1 bash -c "DB_HOST=mysql-8 DB_USERNAME=cmfive_test DB_PASSWORD=cmfive_test DB_DATABASE=cmfive_test DB_PORT=3306 php cmfive.php tests module report silent; exit \$?" + cd test/playwright + npm run build + npm run test --module="report" --reporter="github" if [ $? -gt 0 ]; then echo "Report module tests failed" fi - name: "Run tag module tests" run: | - docker exec nginx-php8.1 bash -c "DB_HOST=mysql-8 DB_USERNAME=cmfive_test DB_PASSWORD=cmfive_test DB_DATABASE=cmfive_test DB_PORT=3306 php cmfive.php tests module tag silent; exit \$?" - if [ $? -gt 0 ]; then - echo "Tag module tests failed" - fi + cd test/playwright + npm run build + npm run test --module="tag" --reporter="github" + if [ $? -gt 0 ]; then + echo "Tag module tests failed" + fi - name: "Run task module tests" run: | - docker exec nginx-php8.1 bash -c "DB_HOST=mysql-8 DB_USERNAME=cmfive_test DB_PASSWORD=cmfive_test DB_DATABASE=cmfive_test DB_PORT=3306 php cmfive.php tests module task silent; exit \$?" - if [ $? -gt 0 ]; then - echo "Task module tests failed" - fi + cd test/playwright + npm run build + npm run test --module="task" --reporter="github" + if [ $? -gt 0 ]; then + echo "Task module tests failed" + fi - name: "Run timelog module tests" run: | - docker exec nginx-php8.1 bash -c "DB_HOST=mysql-8 DB_USERNAME=cmfive_test DB_PASSWORD=cmfive_test DB_DATABASE=cmfive_test DB_PORT=3306 php cmfive.php tests module timelog silent; exit \$?" - if [ $? -gt 0 ]; then - echo "Timelog module tests failed" - fi + cd test/playwright + npm run build + npm run test --module="timelog" --reporter="github" + if [ $? -gt 0 ]; then + echo "Timelog module tests failed" + fi - name: Stop containers # the containers should be stopped regardless of @@ -192,4 +218,6 @@ jobs: path: | test/Codeception/tests/_output/ storage/log/ + test/playwright/test-results/ + test/playwright/playwright-report/ retention-days: 5 diff --git a/system/classes/HtmlBootstrap5.php b/system/classes/HtmlBootstrap5.php index 646aa2c4d..78cfd756b 100644 --- a/system/classes/HtmlBootstrap5.php +++ b/system/classes/HtmlBootstrap5.php @@ -31,6 +31,23 @@ public static function buttonGroup(string $content): string return '
' . $content . '
'; } + public static function dropdownButton($title, $contents, $class) + { + $content = ''; + foreach ($contents as $item) { + $content .= '
  • ' . $item . '
  • '; + } + + return ''; + } + /** * Creates a complex form where each section can have * a different number of columns. @@ -52,7 +69,7 @@ public static function buttonGroup(string $content): string * @param $extrabuttons * @return */ - public static function multiColForm($data, $action = null, $method = "POST", $submitTitle = "Save", $id = null, $class = null, $extrabuttons = null, $target = "_self", $includeFormTag = true, $validation = null) + public static function multiColForm($data, $action = null, $method = "POST", $submitTitle = "Save", $id = null, $class = null, $extrabuttons = null, $target = "_self", $includeFormTag = true, $validation = null, $displayOverlay = true) { if (empty($data)) { return; @@ -64,7 +81,7 @@ public static function multiColForm($data, $action = null, $method = "POST", $su // If form tag is needed print it if ($includeFormTag) { $class .= " col"; - $form->id($id)->name($id)->setClass($class)->method($method)->action($action)->target($target); + $form->id($id)->name($id)->setClass($class)->method($method)->action($action)->target($target)->displayOverlay($displayOverlay); if (in_multiarray("file", $data) || objectPropertyHasValueInMultiArray("\Html\Form\InputField", "type", "file", $data)) { $form->enctype("multipart/form-data"); @@ -126,8 +143,8 @@ public static function multiColForm($data, $action = null, $method = "POST", $su break; } if ((property_exists($field, "type") && $field->type !== "hidden") || !property_exists($field, "type")) { - $buffer .= '
    " - . $field->__toString() . '
    '; + $buffer .= '
    " + . $field->__toString() . '
    '; } else { $buffer .= $field->__toString(); } @@ -162,7 +179,7 @@ public static function multiColForm($data, $action = null, $method = "POST", $su // $buffer .= ($type !== "hidden" ? "
    " : ""); // handle disabled fields - if (substr($name, 0, 1) == '-') { + if (!empty($name) && substr($name, 0, 1) == '-') { $name = substr($name, 1); $readonly = " readonly='true' "; } @@ -173,8 +190,8 @@ public static function multiColForm($data, $action = null, $method = "POST", $su case "email": case "tel": $size = !empty($field[4]) ? $field[4] : null; - $buffer .= '"; + $buffer .= '"; break; case "autocomplete": $options = !empty($field[4]) ? $field[4] : null; @@ -205,14 +222,14 @@ public static function multiColForm($data, $action = null, $method = "POST", $su $custom_class = $field[6]; } $buffer .= '' . $value . ''; + '" ' . (!empty($custom_class) ? ($custom_class === true ? "class='ckeditor'" : "class='$custom_class' ") : '') . ' id="' . $name + . '" ' . $required . '>' . $value . ''; break; case "select": $items = !empty($field[4]) ? $field[4] : null; $default = !empty($field[5]) ? ($field[5] == "null" ? null : $field[5]) : "-- Select --"; - $sl_class = !empty($field[6]) ? $field[6] : null; + $sl_class = !empty($field[6]) ? $field[6] : "form-select"; $buffer .= Html::select($name, $items, $value, $sl_class, "width: 100%;", $default, ($readonly ? ' disabled="disabled" ' : null) . ' ' . $required); break; case "multiSelect": @@ -235,7 +252,7 @@ public static function multiColForm($data, $action = null, $method = "POST", $su $buffer .= Html::radio($name, $group, $value, $defaultValue, $rd_class) . " " . htmlentities($title); break; case "hidden": - $buffer .= ''; + $buffer .= ''; break; case "file": $size = !empty($row[4]) ? $row[4] : null; @@ -284,7 +301,7 @@ public static function table($data, $id = null, $class = "tablesorter", $header $buffer = ""; // Opening tags - $buffer .= ""; + $buffer .= "
    "; if (!empty($header)) { $buffer .= ""; if (is_array($header)) { @@ -626,7 +643,7 @@ public static function filter($legend, $data, $action = null, $method = "POST", switch ($type) { case "text": case "password": - $buffer .= ''; + $buffer .= ''; break; case "autocomplete": $minlength = !empty($row[5]) ? $row[5] : null; @@ -683,7 +700,7 @@ public static function filter($legend, $data, $action = null, $method = "POST", $buffer .= Html::radio($name, $group, $value, $defaultValue, $class) . " " . htmlentities($title); break; case "hidden": - $hidden .= "\n"; + $hidden .= "\n"; break; case "file": $buffer .= ""; @@ -695,8 +712,10 @@ public static function filter($legend, $data, $action = null, $method = "POST", // This is only true when the filter has one element and its a select field if ($should_autosubmit) { - $buffer .= "'; + $selector = $id ? "form#" . $id . " select" : "form select"; + $buffer .= ""; } + // Filter button (optional... though optional is pointless) if (!empty($action)) { $button = new \Html\button(); @@ -712,7 +731,7 @@ public static function filter($legend, $data, $action = null, $method = "POST", $buffer .= ""; } - + $buffer .= ""; // $buffer .= "\n\n"; $buffer .= $hidden . "\n"; @@ -757,7 +776,7 @@ public static function pagination($currentpage, $numpages, $pagesize, $totalresu * @param string $class * @return string */ - public static function alertBox($msg, $type = "alert-info", $include_close = true) : string + public static function alertBox($msg, $type = "alert-info", $include_close = true): string { if ($type !== "alert-info" && $type !== "alert-warning" && $type !== "alert-danger" && $type !== "alert-success") { $type = "alert-info"; diff --git a/system/classes/components/CmfiveStyleComponent.php b/system/classes/components/CmfiveStyleComponent.php index 0287f4b05..b7e773980 100644 --- a/system/classes/components/CmfiveStyleComponent.php +++ b/system/classes/components/CmfiveStyleComponent.php @@ -2,97 +2,101 @@ use ScssPhp\ScssPhp\Compiler; -class CmfiveStyleComponent extends CmfiveComponent { +class CmfiveStyleComponent extends CmfiveComponent +{ - public $_filename; - public $_dirname; - public $_extension = 'css'; - public $_include_paths = []; - public $_external = false; - public static $_allowed_extensions = ['css', 'scss']; + public $_filename; + public $_dirname; + public $_extension = 'css'; + public $_include_paths = []; + public $_external = false; + public static $_allowed_extensions = ['css', 'scss']; - public function __construct($path, $include_paths = [], $is_external = false, $props = []) { - if (!empty($props)) { - foreach($props as $key => $value) { - $this->$key = $value; - } - } + public function __construct($path, $include_paths = [], $is_external = false, $props = []) + { + if (!empty($props)) { + foreach ($props as $key => $value) { + $this->$key = $value; + } + } - $this->_external = $is_external; - if (!$this->_external) { - $style_path = pathinfo($path); + $this->_external = $is_external; + if (!$this->_external) { + $style_path = pathinfo($path); - if (empty($style_path['extension']) || !in_array($style_path['extension'], static::$_allowed_extensions)) { - throw new Exception('Invalid file path given to component'); - } + if (empty($style_path['extension']) || !in_array($style_path['extension'], static::$_allowed_extensions)) { + throw new Exception('Invalid file path given to component'); + } - $this->_extension = $style_path['extension']; - $this->_filename = $style_path['filename']; - $this->_dirname = $style_path['dirname']; - $this->_include_paths = $include_paths; - } else { - $this->href = $path; - } - } + $this->_extension = $style_path['extension']; + $this->_filename = $style_path['filename']; + $this->_dirname = $style_path['dirname']; + $this->_include_paths = $include_paths; + } else { + $this->href = $path; + } + } - public function setProps(Array $props) { - if (!empty($props)) { - foreach($props as $key => $value) { - $this->$key = $value; - } - } + public function setProps(array $props) + { + if (!empty($props)) { + foreach ($props as $key => $value) { + $this->$key = $value; + } + } - return $this; - } + return $this; + } - public function _include() { - switch ($this->_extension) { - case 'scss': { - // Compile and store in cache directory - $scss = new Compiler(); - if (!empty($this->_include_paths)) { - foreach($this->_include_paths as $_include_path) { - $scss->addImportPath(function($_path) use ($_include_path) { - if (file_exists(ROOT_PATH . $_include_path . $_path)) { - return ROOT_PATH . $_include_path . $_path; - } + public function _include() + { + switch ($this->_extension) { + case 'scss': { + // Compile and store in cache directory + $scss = new Compiler(); + if (!empty($this->_include_paths)) { + foreach ($this->_include_paths as $_include_path) { + $scss->addImportPath(function ($_path) use ($_include_path) { + if (file_exists(ROOT_PATH . $_include_path . $_path)) { + return ROOT_PATH . $_include_path . $_path; + } - return null; - }); - } - } + return null; + }); + } + } - try { - $compiled_css = $scss->compileString(file_get_contents(ROOT_PATH . $this->_dirname . '/' . $this->_filename . '.' . $this->_extension)); - } catch (Exception $e) { - // Could not compile SCSS - echo $e->getMessage(); - return; - } - - if (!is_dir(ROOT_PATH . '/cache/css/')) { - mkdir(ROOT_PATH . '/cache/css/'); - - } - // check if exists or make .htaccess with allow from all - if (!file_exists(ROOT_PATH . '/cache/css/.htaccess')) { - $access_file = fopen(ROOT_PATH . '/cache/css/.htaccess', 'w'); - fwrite($access_file, "Allow From All"); - fclose($access_file); - } + try { + $compiled_css = $scss->compileString(file_get_contents(ROOT_PATH . $this->_dirname . '/' . $this->_filename . '.' . $this->_extension)); + } catch (Exception $e) { + // Could not compile SCSS + echo $e->getMessage(); + return; + } - file_put_contents(ROOT_PATH . '/cache/css/' . $this->_filename . '.css', $compiled_css); - $this->rel = 'stylesheet'; - $this->href = '/cache/css/' . $this->_filename . '.css'; - return parent::_include(); - } - case 'css': - default: - $this->rel = 'stylesheet'; - if (!$this->_external) { - $this->href = $this->_dirname . '/' . $this->_filename . '.' . $this->_extension; - } - return parent::_include(); - } - } -} \ No newline at end of file + if (!is_dir(ROOT_PATH . '/cache/css/')) { + mkdir(ROOT_PATH . '/cache/css/'); + } + + // check if exists or make .htaccess with allow from all + if (!file_exists(ROOT_PATH . '/cache/css/.htaccess')) { + $access_file = fopen(ROOT_PATH . '/cache/css/.htaccess', 'w'); + fwrite($access_file, "Allow From All"); + fclose($access_file); + } + + file_put_contents(ROOT_PATH . '/cache/css/' . $this->_filename . '.css', $compiled_css->getCss()); + $this->rel = 'stylesheet'; + $this->href = '/cache/css/' . $this->_filename . '.css'; + return parent::_include(); + } + case 'css': + default: + $this->rel = 'stylesheet'; + if (!$this->_external) { + $this->href = $this->_dirname . '/' . $this->_filename . '.' . $this->_extension; + } + return parent::_include(); + } + } +} diff --git a/system/classes/html/cmfive/CodeMirrorEditor.php b/system/classes/html/cmfive/CodeMirrorEditor.php new file mode 100644 index 000000000..b1c03eaa3 --- /dev/null +++ b/system/classes/html/cmfive/CodeMirrorEditor.php @@ -0,0 +1,63 @@ + ['basicSetup'], + //'parent' => '.code-mirror-target' + ]; + /* + public $_config = [ + 'create' => false, + 'plugins' => ['remove_button'] + ]; + */ + public $_values = []; + + public function getConfig(): array + { + return $this->_config; + } + + public function setConfig(array $config): self + { + $this->_config = $config; + return $this; + } + + /** + * Adds to the config used for codemirror + * + * @param array $config + */ + public function addToConfig(array $config = []): self + { + $this->_config = array_merge($this->_config, $config); + return $this; + } + + public function setValues(array $values): self + { + $this->_values = $values; + return $this; + } + /* + public function __toString(): string + { + if (!empty($this->_values)) { + $this->_config['items'] = $this->_values; + } + $this->setAttribute('data-config', json_encode($this->_config)); + $this->class = $this->class .= ' code-mirror-target'; + + return parent::__toString(); + } +*/ + public function __toString() + { + return '
    value . '\' id="' . $this->id . '">' . '
    '; + } + +} diff --git a/system/classes/html/form.php b/system/classes/html/form.php index 7b58edf15..270f635eb 100755 --- a/system/classes/html/form.php +++ b/system/classes/html/form.php @@ -10,6 +10,7 @@ class form { public $name; public $novalidate; // HTML5 (novalidate) public $target; // (_blank, _self, _parent, _top) + public $displayOverlay; public $id; public $_class; @@ -69,7 +70,14 @@ public function setClass($class) { $this->_class = $class; return $this; } + + public function displayOverlay($displayOverlay) + { + $this->displayOverlay = $displayOverlay; + return $this; + } + public function open() { $buffer = ""; $buffer .= "
    id)) { $buffer .= "id='{$this->id}' "; } - + if (!empty($this->_class)) { $buffer .= "class='{$this->_class}' "; } - - $buffer .= " data-show-overlay >"; + + if (!empty($this->displayOverlay) && $this->displayOverlay === true) { + $buffer .= " data-show-overlay "; + } + + $buffer .= ">"; // Automatically print CSRF token if (class_exists("CSRF") && !empty($this->method) && ($this->method == "POST")) { diff --git a/system/classes/html/form/Banner.php b/system/classes/html/form/Banner.php new file mode 100644 index 000000000..18f7c6178 --- /dev/null +++ b/system/classes/html/form/Banner.php @@ -0,0 +1,99 @@ + + * + * @author Jareem Wheeler jareem@2pisoftware.com + */ +class Banner extends \Html\Form\FormElement +{ + + use \Html\GlobalAttributes, \Html\Events; + + public $form; + public $name; + public $required; + public $value; + + static $_excludeFromOutput = ["value", "label"]; + + /** + * Returns built string of Banner field + * + * @return string representation + */ + public function __toString() + { + $buffer = ' '; + } + + /** + * The form element that the Banner is associated with (its + * "form owner"). The value of the attribute must be the ID of a form + * element in the same document. If this attribute is not specified, the + *