/** * @param array $treeNodes * @return OTreeNode|int * @throws \Exception */ public function getView($treeNodes) { $bright = new Bright(); $tree = new Tree(); $cal = new Calendar(); $maps = new Maps(); $user = new User(); $root = $bright->getRoot(); $numTreeNodes = count($treeNodes); $groups = array(); if ($numTreeNodes > 0) { $child = $root; //new OTreeNode(); for ($i = 0; $i < $numTreeNodes; $i++) { // Check if an alternative parser is required if ($child && isset($child->parser) && (int) $child->parser > 1) { $child->parser = (int) $child->parser; switch ($child->parser) { case Router::$CALENDAR_PARSER: // Must be last item if ($i < $numTreeNodes - 1) { return 404; } $event = $cal->getEventByLabel($treeNodes[$i]); if (!$event) { return 404; } $c = new OTreeNode(); $c->treeId = $child->treeId; $c->page = $event; $c->path = join('/', $treeNodes); return $c; break; case Router::$MARKER_PARSER: // Must be last item if ($i < $numTreeNodes - 1) { return 404; } $marker = $maps->getMarkerByLabel($treeNodes[$i]); if (!$marker) { return 404; } $result = new OTreeNode(); $result->parentId = $child->treeId; $result->page = $marker; $result->path = join('/', $treeNodes); return $result; break; case Router::$USER_PARSER: $userPage = $user->getUserByLabel($treeNodes[$i]); if (!$userPage) { return 404; } $child = new OTreeNode(); $child->page = $userPage; $child->path = join('/', $treeNodes); return $child; break; } } else { $child = $tree->getChildByLabel($child->treeId, $treeNodes[$i]); } if (!$child) { return 404; } if ($child->loginrequired) { $groups = array_merge($groups, $child->requiredgroups); } } // Check if we're member of the required groups $hasAccess = true; if (count($groups) > 0) { $authenticatedUser = $user->getAuthUser(); if ($authenticatedUser) { $missing = array_diff($groups, $authenticatedUser->usergroups); if (count($missing) > 0) { //insufficient rights $hasAccess = false; } } else { $hasAccess = false; } } if ($hasAccess === false) { // Redirect to login $path = BASEURL; $path .= USEPREFIX ? $_SESSION['prefix'] : ''; $path .= LOGINPAGE; // Include treeId, so we can redirect back when login successful header('Location:' . $path . '?tid=' . $child->treeId); exit; } // Build path (no need to get it from the db, we just checked it, it exists :D) $child = $bright->getChild($child->treeId); $child->path = join('/', $treeNodes); return $child; } //ROOT return $root; }
/** * Processes a value from a content row * @param string $value The value to process * @param string $definition The definition of the template * @param string $field The name of the value * @return mixed The processed value */ private function _processValue($value, $definition, $field) { switch ($definition->{$field}->type) { case 'array': $raw = $value; $return = json_decode($value); if ($return == null && ($raw != null && $raw != '')) { // Value is not a json string $return = $raw; } $return = array($return); break; case 'json': try { $return = json_decode($value); } catch (\Exception $ex) { $return = $value; } break; case 'gmaps': try { $return = json_decode($value); $layers = array(); $markers = array(); $polys = array(); $gm_layers = new Layers(); $gm_maps = new Maps(); foreach ($return->layers as $layer) { $l = $gm_layers->getLayer($layer->layerId); if ($l) { $l->visible = $layer->visible; $layers[] = $l; $m = $gm_maps->getMarkers($layer->layerId); $p = $gm_maps->getPolys($layer->layerId); $markers = array_merge($m, $markers); $polys = array_merge($p, $polys); } } $return->layers = $layers; $return->markers = $markers; $return->polys = $polys; } catch (\Exception $ex) { $return = $value; } break; case 'elements': $ids = explode(',', $value); $elements = array(); foreach ($ids as $id) { $page = new Page(); $el = $page->getPageById($id); if ($el) { $elements[] = (object) $el; } } $return = $elements; break; default: $return = $value; } return $return; }