Пример #1
0
function drop_item($id, $interactive = true, $stage = DROPITEM_NORMAL, $force = false)
{
    $a = get_app();
    // locate item to be deleted
    $r = q("SELECT * FROM item WHERE id = %d LIMIT 1", intval($id));
    if (!$r || $r[0]['item_restrict'] & ITEM_DELETED && $stage === DROPITEM_NORMAL) {
        if (!$interactive) {
            return 0;
        }
        notice(t('Item not found.') . EOL);
        goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);
    }
    $item = $r[0];
    $linked_item = $item['resource_id'] ? true : false;
    $ok_to_delete = false;
    // system deletion
    if (!$interactive) {
        $ok_to_delete = true;
    }
    // owner deletion
    if (local_channel() && local_channel() == $item['uid']) {
        $ok_to_delete = true;
    }
    // sys owned item, requires site admin to delete
    $sys = get_sys_channel();
    if (is_site_admin() && $sys['channel_id'] == $item['uid']) {
        $ok_to_delete = true;
    }
    // author deletion
    $observer = $a->get_observer();
    if ($observer && $observer['xchan_hash'] && $observer['xchan_hash'] === $item['author_xchan']) {
        $ok_to_delete = true;
    }
    if ($ok_to_delete) {
        // set the deleted flag immediately on this item just in case the
        // hook calls a remote process which loops. We'll delete it properly in a second.
        $r = q("UPDATE item SET item_restrict = ( item_restrict | %d ) WHERE id = %d", intval($linked_item && !$force ? ITEM_HIDDEN : ITEM_DELETED), intval($item['id']));
        $arr = array('item' => $item, 'interactive' => $interactive, 'stage' => $stage);
        call_hooks('drop_item', $arr);
        $notify_id = intval($item['id']);
        $items = q("select * from item where parent = %d and uid = %d", intval($item['id']), intval($item['uid']));
        if ($items) {
            foreach ($items as $i) {
                delete_item_lowlevel($i, $stage, $force);
            }
        } else {
            delete_item_lowlevel($item, $stage, $force);
        }
        if (!$interactive) {
            return 1;
        }
        // send the notification upstream/downstream as the case may be
        // only send notifications to others if this is the owner's wall item.
        // This isn't optimal. We somehow need to pass to this function whether or not
        // to call the notifier, or we need to call the notifier from the calling function.
        // We'll rely on the undocumented behaviour that DROPITEM_PHASE1 is (hopefully) only
        // set if we know we're going to send delete notifications out to others.
        if ($item['item_flags'] & ITEM_WALL && $stage != DROPITEM_PHASE2 || $stage == DROPITEM_PHASE1) {
            proc_run('php', 'include/notifier.php', 'drop', $notify_id);
        }
        goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);
    } else {
        if (!$interactive) {
            return 0;
        }
        notice(t('Permission denied.') . EOL);
        goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);
    }
}
Пример #2
0
function drop_item($id, $interactive = true, $stage = DROPITEM_NORMAL)
{
    $a = get_app();
    // locate item to be deleted
    $r = q("SELECT * FROM item WHERE id = %d LIMIT 1", intval($id));
    if (!$r || $r[0]['item_restrict'] & ITEM_DELETED && $stage === DROPITEM_NORMAL) {
        if (!$interactive) {
            return 0;
        }
        notice(t('Item not found.') . EOL);
        goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);
    }
    $item = $r[0];
    $ok_to_delete = false;
    // system deletion
    if (!$interactive) {
        $ok_to_delete = true;
    }
    // owner deletion
    if (local_user() && local_user() == $item['uid']) {
        $ok_to_delete = true;
    }
    // author deletion
    $observer = $a->get_observer();
    if ($observer && $observer['xchan_hash'] && $observer['xchan_hash'] === $item['author_xchan']) {
        $ok_to_delete = true;
    }
    if ($ok_to_delete) {
        // set the deleted flag immediately on this item just in case the
        // hook calls a remote process which loops. We'll delete it properly in a second.
        $r = q("UPDATE item SET item_restrict = ( item_restrict | %d ) WHERE id = %d LIMIT 1", intval(ITEM_DELETED), intval($item['id']));
        $arr = array('item' => $item, 'interactive' => $interactive, 'stage' => $stage);
        call_hooks('drop_item', $arr);
        $notify_id = intval($item['id']);
        $items = q("select * from item where parent = %d and uid = %d", intval($item['id']), intval($item['uid']));
        if ($items) {
            foreach ($items as $i) {
                delete_item_lowlevel($i, $stage);
            }
        } else {
            delete_item_lowlevel($item, $stage);
        }
        if (!$interactive) {
            return 1;
        }
        // send the notification upstream/downstream as the case may be
        // only send notifications to others if this is the owner's wall item.
        if ($item['item_flags'] & ITEM_WALL && $stage != DROPITEM_PHASE2) {
            proc_run('php', 'include/notifier.php', 'drop', $notify_id);
        }
        goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);
    } else {
        if (!$interactive) {
            return 0;
        }
        notice(t('Permission denied.') . EOL);
        goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);
    }
}