HFP-1871 Improve addon feature
parent
6959f65022
commit
8c374be79d
|
@ -1993,10 +1993,12 @@ class H5PCore {
|
||||||
|
|
||||||
if (isset($add_to->content->types)) {
|
if (isset($add_to->content->types)) {
|
||||||
foreach($add_to->content->types as $type) {
|
foreach($add_to->content->types as $type) {
|
||||||
if ($this->textAddonMatches($params->params, $type->text->regex)) {
|
|
||||||
|
if (isset($type->text->regex) &&
|
||||||
|
$this->textAddonMatches($params->params, $type->text->regex)) {
|
||||||
$validator->addon($addon);
|
$validator->addon($addon);
|
||||||
|
|
||||||
// Addon can only be added once
|
// An addon shall only be added once
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2079,39 +2081,29 @@ class H5PCore {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if params contain math.
|
* Determine if params contain any match.
|
||||||
*
|
*
|
||||||
* @param {object} params - Parameters.
|
* @param {object} params - Parameters.
|
||||||
* @param {string} [mathPattern] - Regular expression to identify math.
|
* @param {string} [pattern] - Regular expression to identify pattern.
|
||||||
* @param {boolean} [found] - Used for recursion.
|
* @param {boolean} [found] - Used for recursion.
|
||||||
* @return {boolean} True, if params contain math.
|
* @return {boolean} True, if params matches pattern.
|
||||||
*/
|
*/
|
||||||
private function textAddonMatches($params, $mathPattern, $found = false) {
|
private function textAddonMatches($params, $pattern, $found = false) {
|
||||||
if (!isset($mathPattern)) {
|
$type = gettype($params);
|
||||||
$mathPattern = '/\$\$.+\$\$|\\\[.+\\\]|\\\(.+\\\)/';
|
if ($type === 'string') {
|
||||||
}
|
if (preg_match($pattern, $params) === 1) {
|
||||||
foreach($params as $property => $value) {
|
return true;
|
||||||
if (gettype($value) === 'string') {
|
|
||||||
if (preg_match($mathPattern, $value) === 1) {
|
|
||||||
$found = true;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($found === false) {
|
elseif ($type === 'array' || $type === 'object') {
|
||||||
if (gettype($value) === 'array') {
|
foreach ($params as $value) {
|
||||||
for ($i = 0; $i < sizeof($value); $i++) {
|
$found = $this->textAddonMatches($value, $pattern, $found);
|
||||||
$found = $this->textAddonMatches($value[$i], $mathPattern, $found);
|
|
||||||
if ($found === true) {
|
if ($found === true) {
|
||||||
break;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (gettype($value) === 'object') {
|
return false;
|
||||||
$found = $this->textAddonMatches($value, $mathPattern, $found);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $found;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue