Ejemplo n.º 1
0
function uexport_init(&$a)
{
    if (!local_channel()) {
        killme();
    }
    if (argc() > 1) {
        $channel = App::get_channel();
        require_once 'include/identity.php';
        if (argc() > 1 && intval(argv(1)) > 1900) {
            $year = intval(argv(1));
        }
        if (argc() > 2 && intval(argv(2)) > 0 && intval(argv(2)) <= 12) {
            $month = intval(argv(2));
        }
        header('content-type: application/octet_stream');
        header('content-disposition: attachment; filename="' . $channel['channel_address'] . ($year ? '-' . $year : '') . ($month ? '-' . $month : '') . '.json"');
        if ($year) {
            echo json_encode(identity_export_year(local_channel(), $year, $month));
            killme();
        }
        if (argc() > 1 && argv(1) === 'basic') {
            echo json_encode(identity_basic_export(local_channel()));
            killme();
        }
        // FIXME - this basically doesn't work in the wild with a channel more than a few months old due to memory and execution time limits.
        // It probably needs to be built at the CLI and offered to download as a tarball.  Maybe stored in the members dav.
        if (argc() > 1 && argv(1) === 'complete') {
            echo json_encode(identity_basic_export(local_channel(), true));
            killme();
        }
    }
}
Ejemplo n.º 2
0
function export_items(&$a, $channel_hash, $year, $month)
{
    if (validatesAsInt($year) && validatesAsInt($month)) {
    } else {
        json_error_die(422, 'Unprocessable Entity', 'Month and year must be numbers' . $month . " " . $year);
    }
    if ($month < 1 || $month > 12) {
        json_error_die(422, 'Unprocessable Entity', 'Invalid month' . $month);
    }
    if ($year < 1 || $year > date('Y')) {
        json_error_die(422, 'Unprocessable Entity', 'Are you from the future? Invalid year ' . $year);
    }
    $items = identity_export_year(get_channel_id($channel_hash), $year, $month);
    if (count($items) < 1) {
        json_error_die(404, 'Not Found', "No posts for {$channel_hash} on {$year}-{$month}");
    }
    json_return_and_die($items);
}