+ return $o;
+}
+
+/**
+ * @param int $id
+ * @param string $return
+ * @return string
+ * @throws HTTPException\InternalServerErrorException
+ */
+function drop_item(int $id, string $return = '')
+{
+ // locate item to be deleted
+ $fields = ['id', 'uid', 'guid', 'contact-id', 'deleted', 'gravity', 'parent'];
+ $item = Item::selectFirstForUser(local_user(), $fields, ['id' => $id]);
+
+ if (!DBA::isResult($item)) {
+ notice(DI::l10n()->t('Item not found.'));
+ DI::baseUrl()->redirect('network');
+ }
+
+ if ($item['deleted']) {
+ return '';
+ }
+
+ $contact_id = 0;
+
+ // check if logged in user is either the author or owner of this item
+ if (Session::getRemoteContactID($item['uid']) == $item['contact-id']) {
+ $contact_id = $item['contact-id'];
+ }
+
+ if ((local_user() == $item['uid']) || $contact_id) {
+ if (!empty($item['parent'])) {
+ $parentitem = Item::selectFirstForUser(local_user(), ['guid'], ['id' => $item['parent']]);
+ }
+
+ // delete the item
+ Item::deleteForUser(['id' => $item['id']], local_user());
+
+ $return_url = hex2bin($return);
+
+ // 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) {
+ // 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
+ }