documentIdentifier; $fragment = (!strlen($fragment) || strpos($fragment, '#') === true) ? $fragment : '#' . $fragment; // Disable redirecting to same document if ($to == 'document' && $id == $modx->documentIdentifier) { return; } $redirect = $modx->makeUrl($modx->config['error_page']); switch ($to) { case 'document': // To document $redirect = $modx->makeUrl($id) . $fragment; break; case 'parent': // To parent $docObj = $modx->getDocumentObject('id', $id); $redirect = $modx->makeUrl($docObj['parent']) . $fragment; break; case 'child': // To child if (!strlen($child)) { $method = 'auto'; } else if (is_numeric($child) && !$modx->documentListing[$child]) { $method = 'id'; } else { $method = 'alias'; } $children = $modx->getActiveChildren($id, 'id', 'ASC', 'id, alias'); if ($children !== false) { foreach ($children as $value) { $isChild = ($method == 'auto') || (($method == 'id' && $value['id'] == $child) || ($method == 'alias' && $value['alias'] == $child)); if ($isChild) { $redirect = $modx->makeUrl($value['id']) . $fragment; break; } } } break; default: break; } return $modx->sendRedirect($redirect); ?>