extension = $extension; } public function process_actions($page) { if (!$page || !$this->extension) { return $page; } if (isset($page['actions']) && !empty($page['actions'])) { foreach ($page['actions'] as $action) { $page = $this->process_action($page, $action); } if (isset($page['hidden']) && $page['hidden']) { $page = false; } } if ($page) { if (!empty($page['elements'])) { foreach ($page['elements'] as $el_key => $el_value) { if (isset($el_value['actions']) && !empty($el_value['actions'])) { foreach ($el_value['actions'] as $action) { $el_value = $this->process_action($el_value, $action); } $page['elements'][$el_key] = $el_value; if (isset($el_value['hidden']) && $el_value['hidden']) { unset($page['elements'][$el_key]); break; } } } } } return $page; } private function process_action($element, $action) { $apply = false; if (isset($action['conditions']) && !empty($action['conditions'])) { foreach ($action['conditions'] as $condition) { $apply = $this->process_condition($condition); if ($action['apply'] == 'any' && $apply) { break; } elseif ($action['apply'] == 'all' && !$apply) { break; } } } if ($apply) { $element = $this->apply_action($element, $action); } return $element; } private function process_condition($condition) { $result = false; $if = $this->extension->render($condition['if']); $value = $this->extension->render($condition['value']); switch ($condition['condition']) { case '=': $result = $if == $value ? true : false; break; case '!=': $result = $if != $value ? true : false; break; case '>': $result = $if > $value ? true : false; break; case '>=': $result = $if >= $value ? true : false; break; case '<': $result = $if < $value ? true : false; break; case '<=': $result = $if <= $value ? true : false; break; case 'like': $result = strpos($if, $value) !== false ? true : false; break; case 'not_like': $result = strpos($if, $value) === false ? true : false; break; } return $result; } private function apply_action($element, $action) { if ($action['action'] == 'hide') { $element['hidden'] = true; } elseif ($action['action'] == 'show') { $element['hidden'] = false; } elseif ($action['action'] == 'change' && $action['property']) { $number_properties = array( 'width', 'height', 'left', 'top' ); $not_properties = array( 'top', 'left', 'width', 'height', 'value' ); $change = $this->extension->render($action['change']); if ((substr($change, 0, 1) === "+" || substr($change, 0, 1) === "-") && in_array($action['property'], $number_properties)) { if (isset($element['element_id'])) { $value = isset($element[$action['property']]) ? $element[$action['property']] : 0; } else { $value = isset($element['properties'][$action['property']]) ? $element['properties'][$action['property']] : 0; } $change = $value + floatval($change); } if (in_array($action['property'], $not_properties) && isset($element['element_id'])) { $element[$action['property']] = $change; } else { $element['properties'][$action['property']] = $change; } } return $element; } }