Skip to content

Commit

Permalink
Merge branch 'develop' into fix/207-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-buckley authored Mar 19, 2024
2 parents 3d656fd + a136a90 commit 4cd903a
Show file tree
Hide file tree
Showing 246 changed files with 10,508 additions and 68,690 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2
updates:
- package-ecosystem: "github-actions" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- Have you made sure the following is correct? -->
## 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).
Expand Down
316 changes: 205 additions & 111 deletions .github/workflows/ci.yml

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions .github/workflows/dependencies.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: 'Dependency Review'
on: [pull_request]

permissions:
contents: read

jobs:
dependency-review:
runs-on: ubuntu-latest
steps:
- name: 'Checkout Repository'
uses: actions/checkout@v4
- name: 'Dependency Review'
uses: actions/dependency-review-action@v4
with:
warn-only: true
25 changes: 0 additions & 25 deletions .github/workflows/stale.yml

This file was deleted.

8 changes: 8 additions & 0 deletions system/classes/DbService.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ public function __construct(Web $w)
$this->w = $w;
}

/**
* @return MenuLinkType[]
*/
public function navList(): array
{
return [];
}

/**
* Formats a timestamp
* per default MySQL datetime format is used
Expand Down
2 changes: 1 addition & 1 deletion system/classes/History.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public static function remove($object = null)
*/
private static function sort($a, $b)
{
return $a['time'] - $b['time'];
return $b['time'] - $a['time'];
}

/**
Expand Down
53 changes: 36 additions & 17 deletions system/classes/HtmlBootstrap5.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,23 @@ public static function buttonGroup(string $content): string
return '<div class="btn-group btn-group-sm" role="group">' . $content . '</div>';
}

public static function dropdownButton($title, $contents, $class)
{
$content = '';
foreach ($contents as $item) {
$content .= '<li>' . $item . '</li>';
}

return '<div class="dropdown">
<button class="' . $class . ' dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">'
. $title .
'</button>
<ul class="dropdown-menu">'
. $content .
'</ul>
</div>';
}

/**
* Creates a complex form where each section can have
* a different number of columns.
Expand All @@ -52,7 +69,7 @@ public static function buttonGroup(string $content): string
* @param <type> $extrabuttons
* @return <type>
*/
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;
Expand All @@ -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");
Expand Down Expand Up @@ -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 .= '<div class="col"><label class="' . $label_class . '"' . (property_exists($field, 'id') && !empty($field->id) ? ' for="' . $field->id . '"' : '' ) . '>' . $field->label . ($field->required ? " <small>Required</small>" : "") . "</label>"
. $field->__toString() . '</div>';
$buffer .= '<div class="col"><label class="' . $label_class . '"' . (property_exists($field, 'id') && !empty($field->id) ? ' for="' . $field->id . '"' : '') . '>' . $field->label . ($field->required ? " <small>Required</small>" : "") . "</label>"
. $field->__toString() . '</div>';
} else {
$buffer .= $field->__toString();
}
Expand Down Expand Up @@ -162,7 +179,7 @@ public static function multiColForm($data, $action = null, $method = "POST", $su
// $buffer .= ($type !== "hidden" ? "<div>" : "");

// handle disabled fields
if (substr($name, 0, 1) == '-') {
if (!empty($name) && substr($name, 0, 1) == '-') {
$name = substr($name, 1);
$readonly = " readonly='true' ";
}
Expand All @@ -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 .= '<input' . $readonly . ' class="form-control" type="' . $type . '" name="' . $name . '" value="' . htmlspecialchars($value) .
'" size="' . $size . '" id="' . $name . '" ' . $required . " />";
$buffer .= '<input' . $readonly . ' class="form-control" type="' . $type . '" name="' . $name . '" value="' . (empty($value) ? '' : htmlspecialchars($value)) .
'" size="' . $size . '" id="' . $name . '" ' . $required . " />";
break;
case "autocomplete":
$options = !empty($field[4]) ? $field[4] : null;
Expand Down Expand Up @@ -205,14 +222,14 @@ public static function multiColForm($data, $action = null, $method = "POST", $su
$custom_class = $field[6];
}
$buffer .= '<textarea' . $readonly . ' class="form-control" style="width:100%; height: auto; " name="' . $name . '" rows="' . $r . '" cols="' . $c .
'" ' . (!empty($custom_class) ? ($custom_class === true ? "class='ckeditor'" : "class='$custom_class' ") : '') . ' id="' . $name
. '" ' . $required . '>' . $value . '</textarea>';
'" ' . (!empty($custom_class) ? ($custom_class === true ? "class='ckeditor'" : "class='$custom_class' ") : '') . ' id="' . $name
. '" ' . $required . '>' . $value . '</textarea>';
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":
Expand All @@ -235,7 +252,7 @@ public static function multiColForm($data, $action = null, $method = "POST", $su
$buffer .= Html::radio($name, $group, $value, $defaultValue, $rd_class) . "&nbsp;" . htmlentities($title);
break;
case "hidden":
$buffer .= '<input type="hidden" name="' . $name . '" value="' . htmlspecialchars($value) . '" id="' . $name . '"/>';
$buffer .= '<input type="hidden" name="' . $name . '" value="' . (empty($value) ? '' : htmlspecialchars($value)) . '" id="' . $name . '"/>';
break;
case "file":
$size = !empty($row[4]) ? $row[4] : null;
Expand Down Expand Up @@ -284,7 +301,7 @@ public static function table($data, $id = null, $class = "tablesorter", $header
$buffer = "";

// Opening tags
$buffer .= "<table class='{$class} d-none d-md-block'>";
$buffer .= "<table class='{$class} d-none d-md-table'>";
if (!empty($header)) {
$buffer .= "<thead><tr>";
if (is_array($header)) {
Expand Down Expand Up @@ -626,7 +643,7 @@ public static function filter($legend, $data, $action = null, $method = "POST",
switch ($type) {
case "text":
case "password":
$buffer .= '<input' . $readonly . ' style="width:100%;" type="' . $type . '" name="' . $name . '" value="' . htmlspecialchars($value) . '" size="' . (!empty($row[4]) ? $row[4] : null) . '" id="' . $name . '"/>';
$buffer .= '<input' . $readonly . ' style="width:100%;" type="' . $type . '" name="' . $name . '" value="' . (empty($value) ? '' : htmlspecialchars($value)) . '" size="' . (!empty($row[4]) ? $row[4] : null) . '" id="' . $name . '"/>';
break;
case "autocomplete":
$minlength = !empty($row[5]) ? $row[5] : null;
Expand Down Expand Up @@ -683,7 +700,7 @@ public static function filter($legend, $data, $action = null, $method = "POST",
$buffer .= Html::radio($name, $group, $value, $defaultValue, $class) . "&nbsp;" . htmlentities($title);
break;
case "hidden":
$hidden .= "<input type=\"hidden\" name=\"" . $name . "\" value=\"" . htmlspecialchars($value) . "\"/>\n";
$hidden .= "<input type=\"hidden\" name=\"" . $name . "\" value=\"" . (empty($value) ? '' : htmlspecialchars($value)) . "\"/>\n";
break;
case "file":
$buffer .= "<input style=\"width:100%;\" type=\"" . $type . "\" name=\"" . $name . "\" size=\"" . $size . "\" id=\"" . $name . "\"/>";
Expand All @@ -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 .= "<script>$('form" . ($id ? "#" . $id : "") . ' select\').change(function(){this.form.submit()});</script>';
$selector = $id ? "form#" . $id . " select" : "form select";
$buffer .= "<script>document.querySelectorAll('" . $selector . "').forEach(function(select) { select.addEventListener('change', function() { this.form.submit(); }); });</script>";
}

// Filter button (optional... though optional is pointless)
if (!empty($action)) {
$button = new \Html\button();
Expand All @@ -712,7 +731,7 @@ public static function filter($legend, $data, $action = null, $method = "POST",

$buffer .= "</div></label></li>";
}

$buffer .= "</ul>"; // </div>
$buffer .= "\n</fieldset>\n";
$buffer .= $hidden . "</form>\n";
Expand Down Expand Up @@ -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";
Expand Down
18 changes: 18 additions & 0 deletions system/classes/MenuLinkStruct.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

enum MenuLinkType {
case Link;
case Modal;
}

class MenuLinkStruct {
public function __construct(
public string $title,
public string $url,
public MenuLinkType $type = MenuLinkType::Link,
) {
if ($url[0] !== '/') {
$this->url = '/' . $url;
}
}
}
91 changes: 46 additions & 45 deletions system/classes/components/CmfiveComponent.php
Original file line number Diff line number Diff line change
@@ -1,47 +1,48 @@
<?php

abstract class CmfiveComponent {

public $tag = 'link';
public $has_closing_tag = false;

public $is_included = false;

// The weight is an integer that allows cmfive to organise the load order of components
// Higher numbers will appear first
public $weight = 1000;
public static $_excludeFromOutput = ['tag', 'has_closing_tag', 'is_included', 'weight'];

/**
* Returns the HTML to include this component on the page
*
* @return string component include code
*/
public function _include() {
if ($this->is_included) {
return '';
}

$this->is_included = true;

$buffer = '<' . $this->tag . ' ';

foreach(get_object_vars($this) as $field => $value) {
if (!in_array($field, static::$_excludeFromOutput) && strpos($field, '_') !== 0) {
$buffer .= $field . ($value !== null ? '=\'' . $value . '\' ' : ' ');
}
}

return $buffer . ($this->has_closing_tag ? '></' . $this->tag . '>' : '/>');
}

/**
* Should return the component itself, some components may not need this like link/script components
*
* @return string component
*/
public function display($binding_data = []) {
return '';
}

}
abstract class CmfiveComponent
{
public $tag = 'link';
public $has_closing_tag = false;

public $is_included = false;

// The weight is an integer that allows cmfive to organise the load order of components
// Higher numbers will appear first
public $weight = 1000;
public static $_excludeFromOutput = ['tag', 'has_closing_tag', 'is_included', 'weight'];

/**
* Returns the HTML to include this component on the page
*
* @return string component include code
*/
public function _include()
{
if ($this->is_included) {
return '';
}

$this->is_included = true;

$buffer = '<' . $this->tag . ' ';

foreach (get_object_vars($this) as $field => $value) {
if (!in_array($field, static::$_excludeFromOutput) && strpos($field, '_') !== 0) {
$buffer .= $field . ($value !== null ? '=\'' . $value . '\' ' : ' ');
}
}

return $buffer . ($this->has_closing_tag ? '></' . $this->tag . '>' : '/>');
}

/**
* Should return the component itself, some components may not need this like link/script components
*
* @return string component
*/
public function display($binding_data = [])
{
return '';
}
}
13 changes: 13 additions & 0 deletions system/classes/components/CmfiveScriptComponentRegister.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,17 @@ public static function outputScripts() {
}, static::getComponents() ? : []);
}

public static function requireVue3()
{
static::registerComponent('vue3', new CmfiveScriptComponent('/system/templates/base/node_modules/vue3/dist/vue.global.prod.js'));
if (array_key_exists('vue2', static::$_register)) {
unset(static::$_register['vue2']);
}
}

public static function requireVue2()
{
static::registerComponent('vue2', new CmfiveScriptComponent('/system/templates/js/vue.js'));
}

}
Loading

0 comments on commit 4cd903a

Please sign in to comment.