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) {
|
}
|
||||||
if (gettype($value) === 'array') {
|
elseif ($type === 'array' || $type === 'object') {
|
||||||
for ($i = 0; $i < sizeof($value); $i++) {
|
foreach ($params as $value) {
|
||||||
$found = $this->textAddonMatches($value[$i], $mathPattern, $found);
|
$found = $this->textAddonMatches($value, $pattern, $found);
|
||||||
if ($found === true) {
|
if ($found === true) {
|
||||||
break;
|
return true;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (gettype($value) === 'object') {
|
|
||||||
$found = $this->textAddonMatches($value, $mathPattern, $found);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $found;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue