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
120 changes: 60 additions & 60 deletions source/php/Component/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ class BaseController
*/
protected $data = array(
'id' => '', //Unique dom id
'class' => "", //Auto compiled from class list on data fetch
'baseClass' => "",
'class' => '', //Auto compiled from class list on data fetch
'baseClass' => '',
'classList' => [], //An array of class names (push classes here),
'attribute' => "",
'attribute' => '',
'attributeList' => [],
'context' => [],
'isBlock' => false,
'isShortcode' => false
'isShortcode' => false,
);

/**
Expand All @@ -37,9 +37,8 @@ class BaseController
public function __construct(
$data,
protected CacheInterface $cache,
protected TagSanitizerInterface $tagSanitizer
protected TagSanitizerInterface $tagSanitizer,
) {

//Load input data
if (!is_null($data) && is_array($data)) {
$this->data = array_merge($this->data, $data);
Expand All @@ -51,18 +50,18 @@ public function __construct(
} elseif (is_string($this->data['context'])) {
$this->data['context'] = [
$this->data['context'],
$this->createDefaultContext($this)
$this->createDefaultContext($this),
];
}

//Applies a general wp filter
if (function_exists('apply_filters')) {
$this->data = apply_filters("ComponentLibrary/Component/Data", $this->data);
$this->data = apply_filters('ComponentLibrary/Component/Data', $this->data);
}

//Applies a general wp filter
if (function_exists('apply_filters')) {
$this->data = apply_filters($this->createFilterName($this) . DIRECTORY_SEPARATOR . "Data", $this->data);
$this->data = apply_filters($this->createFilterName($this) . DIRECTORY_SEPARATOR . 'Data', $this->data);
}

if (function_exists('apply_filters')) {
Expand Down Expand Up @@ -108,11 +107,11 @@ public function getData()
if (function_exists('apply_filters')) {
if (is_array($data) && !empty($data)) {
foreach ($data as $key => $item) {
if (!in_array($key, array("data", "classes", 'class'))) {
if (!in_array($key, array('data', 'classes', 'class'))) {
$data[$key] = apply_filters(
$this->createFilterName($this) . DIRECTORY_SEPARATOR . ucfirst($key),
$this->createFilterName($this) . DIRECTORY_SEPARATOR . ucfirst($key),
$data[$key],
$data['context'] ?? []
$data['context'] ?? [],
);
}
}
Expand All @@ -131,9 +130,9 @@ public function getData()
private function getId()
{
if (isset($this->data['id']) && !empty($this->data['id'])) {
return (string) str_replace(" ", "", ($this->data['id']));
return (string) str_replace(' ', '', $this->data['id']);
}
return "";
return '';
}

/**
Expand All @@ -149,14 +148,14 @@ public function getUid()
return $this->uid = uniqid();
}

/**
* If the slot exists in the data array, and the html property of the slot is not empty, then
* return true
*
* @param slotKey The name of the slot you want to check.
*
* @return a boolean value.
*/
/**
* If the slot exists in the data array, and the html property of the slot is not empty, then
* return true
*
* @param slotKey The name of the slot you want to check.
*
* @return a boolean value.
*/
/**
* Checks if the specified slot contains data.
*
Expand All @@ -169,7 +168,7 @@ public function slotHasData($slotKey)
return false;
}

$property = ($slotKey === 'slot') ? 'html' : 'contents';
$property = $slotKey === 'slot' ? 'html' : 'contents';
$value = $this->accessProtected($this->data[$slotKey], $property);

return !empty($value);
Expand All @@ -180,7 +179,7 @@ private function getNamespaceParts()
//Get all parts of the location
return explode(
"\\",
get_called_class()
get_called_class(),
);
}

Expand All @@ -189,7 +188,7 @@ private function setModifier($class, $modifier)
if (!empty($modifier)) {
foreach ($modifier as &$value) {
if ($value && is_string($value)) {
$class[] = $this->getBaseClass() . '--' . $value;
$class[] = $this->getBaseClass() . '--' . $value;
}
}
}
Expand All @@ -212,7 +211,7 @@ private function validClassList($classList): bool

if (is_array($classList) && !empty($classList)) {
foreach ($classList as $classListItem) {
if (strpos($classListItem, " ")) {
if (strpos($classListItem, ' ')) {
return false;
}
if (empty($classListItem)) {
Expand All @@ -236,46 +235,46 @@ private function getClass($implode = true)
'The parameter classList is not allowed to contain spaces or include empty strings.
Multiple classes may be separated by entering a array of items.
Please review data inputted: %s',
print_r($this, true)
print_r($this, true),
),
E_USER_WARNING
E_USER_WARNING,
);
}

//Store locally
if (isset($this->data['classList']) && is_array($this->data['classList'])) {
array_unshift(
$this->data['classList'],
(string) $this->getBaseClass()
(string) $this->getBaseClass(),
);
$class = (array) $this->data['classList'];
} else {
$class = array();
}

$namespaceParts = $this->getNameSpaceParts();
$namespaceParts = $this->getNameSpaceParts();
$componentName = end($namespaceParts);

//Applies a general wp filter
if (function_exists('apply_filters')) {
$modifier = apply_filters("ComponentLibrary/Component/Modifier", [], $this->data['context']);
$modifier = apply_filters('ComponentLibrary/Component/Modifier', [], $this->data['context']);
$class = $this->setModifier($class, $modifier);
}

//Applies component specific wp filter
if (function_exists('apply_filters')) {
$modifier = apply_filters("ComponentLibrary/Component/". $componentName ."/Modifier", [], $this->data['context']);
$modifier = apply_filters('ComponentLibrary/Component/' . $componentName . '/Modifier', [], $this->data['context']);
$class = $this->setModifier($class, $modifier);
}

//Applies a general wp filter
if (function_exists('apply_filters')) {
$class = apply_filters("ComponentLibrary/Component/Class", $class);
$class = apply_filters('ComponentLibrary/Component/Class', $class);
}

//Applies component specific wp filter
if (function_exists('apply_filters')) {
$class = apply_filters("ComponentLibrary/Component/". $componentName ."/Class", $class, $this->data['context']);
$class = apply_filters('ComponentLibrary/Component/' . $componentName . '/Class', $class, $this->data['context']);
}

//Return manipulated classes as array
Expand All @@ -284,7 +283,7 @@ private function getClass($implode = true)
}

//Return manipulated data array as string
return (string) implode(" ", (array) $class);
return (string) implode(' ', (array) $class);
}

/**
Expand All @@ -307,7 +306,7 @@ private function getContainerAware()
*
* @return string A single css class
*/
protected function getBaseClass(string $className = "", bool $isModifier = false): string
protected function getBaseClass(string $className = '', bool $isModifier = false): string
{
//If base class is specified from component controller then use that
if ($this->data['baseClass']) {
Expand All @@ -318,19 +317,19 @@ protected function getBaseClass(string $className = "", bool $isModifier = false
$namespaceParts = $this->getNamespaceParts();

//Separator notation
$separator = ($isModifier ? '--' : '__');
$separator = $isModifier ? '--' : '__';

//Create array of items
return strtolower(
implode(
"",
'',
[
"c-",
'c-',
end($namespaceParts),
($className ? $separator : ''),
$className
]
)
$className ? $separator : '',
$className,
],
),
);
}

Expand All @@ -345,7 +344,7 @@ private function getAttribute($implode = true)

//Add attribute for container awareness
if ($this->getContainerAware() == true) {
$attribute['data-observe-resizes'] = "";
$attribute['data-observe-resizes'] = '';
}

//Add id if defined
Expand All @@ -358,12 +357,12 @@ private function getAttribute($implode = true)

//Applies a general wp filter
if (function_exists('apply_filters')) {
$attribute = apply_filters($this->createFilterName($this) . DIRECTORY_SEPARATOR . "Attribute", $attribute);
$attribute = apply_filters($this->createFilterName($this) . DIRECTORY_SEPARATOR . 'Attribute', $attribute);
}

//Applies a general wp filter
if (function_exists('apply_filters')) {
$attribute = apply_filters("ComponentLibrary/Component/Attribute", $attribute);
$attribute = apply_filters('ComponentLibrary/Component/Attribute', $attribute);
}

//Sanitize "broken" css.
Expand Down Expand Up @@ -395,14 +394,15 @@ private function getAttribute($implode = true)

/**
* Santitize the id attribute of a component
*
* This will prevent invalid characters and ensure that the id
*
* This will prevent invalid characters and ensure that the id
* starts with a letter as required by the HTML spec.
*
*
* @param string $id The id to sanitize
* @return string The sanitized id
*/
public function sanitizeIdAttribute(string $id): string {
public function sanitizeIdAttribute(string $id): string
{
// Allow a-z, A-Z, 0-9, -, _, [, ], {, }
$id = preg_replace('/[^a-zA-Z0-9\-\_\[\]\{\}]/', '', $id);

Expand All @@ -425,7 +425,7 @@ public function sanitizeInlineCss($inlineCss)

/**
* Builds a string of attributes.
*
*
* @param array $attributes An array of attributes to be added to the string.
* @return string A string of attributes.
*/
Expand All @@ -434,7 +434,7 @@ public static function buildAttributes(array $attributes): string
$attributeStrings = [];

foreach ($attributes as $key => $value) {
if(is_resource($value) || (!is_string($value) && is_callable($value))) {
if (is_resource($value) || !is_string($value) && is_callable($value)) {
continue;
}

Expand All @@ -450,12 +450,12 @@ public static function buildAttributes(array $attributes): string
$value = $value ? '1' : '0';
}

if($value === "null" || $value === null) {
$escapedValue = "";
if ($value === 'null' || $value === null) {
$escapedValue = '';
} else {
$escapedValue = htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
}

$attributeStrings[] = "$key=\"$escapedValue\"";
}

Expand All @@ -471,8 +471,8 @@ function ($v, $k) {
return sprintf('%s: %s;', $k, $v);
},
array_values($styles),
array_keys($styles)
)
array_keys($styles),
),
);
}

Expand All @@ -486,7 +486,7 @@ public function createFilterName($class)
//Get all parts of the location
$name = explode(
"\\",
get_class($class)
get_class($class),
);

//Remove duplicates
Expand All @@ -506,7 +506,7 @@ private function createDefaultContext($class)
//Get all parts of the location
$name = explode(
"\\",
get_class($class)
get_class($class),
);

if (isset($name[0])) {
Expand All @@ -517,7 +517,7 @@ private function createDefaultContext($class)
$name = array_unique($name);

//Create string
return strtolower(implode(".", $name));
return strtolower(implode('.', $name));
}

/**
Expand Down
10 changes: 5 additions & 5 deletions source/php/Component/Fileinput/Fileinput.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function init()
$maxFileSize = $this->determineMaxSize($maxSize, $acceptedTypesArray);

if (!empty($maxFileSize)) {
$this->data['maxSize'] = ($this->data['lang']->maximumSize ?? 'Maximum size') . ': ' . $maxFileSize . ' MB';
$this->data['maxSize'] = ($this->data['maximumSizeLabel']) . ': ' . $maxFileSize . ' MB';
$this->data['attributeList']['data-js-file-max-size'] = $maxFileSize;
}

Expand Down Expand Up @@ -124,13 +124,13 @@ private function determineMaxSize(int|string|null $maxSize, array $accept): null

private function createAcceptedFilesList(array $accept): string
{
return ($this->data['lang']->allowedFiles ?? 'Allowed files') . ': ' . implode(' ', array_map(function ($type) {
return ($this->data['allowedFileTypesLabel']) . ': ' . implode(' ', array_map(function ($type) {
if ($type === 'video/*')
return $this->data['lang']->videos ?? 'Videos';
return $this->data['fileTypeVideosLabel'];
if ($type === 'image/*')
return $this->data['lang']->images ?? 'Images';
return $this->data['fileTypeImagesLabel'];
if ($type === 'audio/*')
return $this->data['lang']->audios ?? 'Audios';
return $this->data['fileTypeAudioLabel'];
return $type;
}, $accept));
}
Expand Down
Loading
Loading