+
+function item_redirect_after_action($item, $returnUrlHex)
+{
+ $return_url = hex2bin($returnUrlHex);
+
+ // removes update_* from return_url to ignore Ajax refresh
+ $return_url = str_replace("update_", "", $return_url);
+
+ // Check if delete a comment
+ if ($item['gravity'] == GRAVITY_COMMENT) {
+ if (!empty($item['parent'])) {
+ $parentitem = Post::selectFirstForUser(local_user(), ['guid'], ['id' => $item['parent']]);
+ }
+
+ // Return to parent guid
+ if (!empty($parentitem)) {
+ DI::baseUrl()->redirect('display/' . $parentitem['guid']);
+ //NOTREACHED
+ } // In case something goes wrong
+ else {
+ DI::baseUrl()->redirect('network');
+ //NOTREACHED
+ }
+ } else {
+ // if unknown location or deleting top level post called from display
+ if (empty($return_url) || strpos($return_url, 'display') !== false) {
+ DI::baseUrl()->redirect('network');
+ //NOTREACHED
+ } else {
+ DI::baseUrl()->redirect($return_url);
+ //NOTREACHED
+ }
+ }
+}