Exemplo n.º 1
0
            $output->writeln("Unsubscribing from {$subscription['topic']}");
            if ($subscription['hub'] == $dh->getUrl()) {
                $unsubhub = $dh;
            } else {
                $unsubhub = new Subscriptions\PushHub($subscription['hub']);
            }
            $output->writeln(" -> Unsubscribing from hub: {$unsubhub}");
            $callback = $app['url_generator']->generate('subscriptions.id.ping', ['id' => $subscription['id']], true);
            $result = $unsubhub->unsubscribe($subscription['topic'], $callback);
            if ($result instanceof Exception) {
                $output->writeln(" -> ERROR: {$result->getMessage()}");
            }
        }
        $output->writeln("Re-subscribing to {$subscription['topic']} (ID {$subscription['id']})");
        try {
            list($newSub, $err) = Subscriptions\subscribe($app, $subscription['topic']);
        } catch (Exception $err) {
        }
        if ($err) {
            $output->writeln(" -> ERROR: {$err->getMessage()}");
        }
        $output->writeln('');
    }
});
$console->register('prune')->setDescription('Unsubscribe from any feeds which are no longer in anyone’s columns')->setCode(function (InputInterface $input, OutputInterface $output) use($app) {
    /** @var Subscriptions\PushHub $dh */
    $dh = $app['subscriptions.defaulthub'];
    $rq = new Routing\RequestContext(null, null, $app['host'], 'https');
    $app['url_generator']->setContext($rq);
    $allTopics = [];
    foreach (glob(__DIR__ . '/../data/*') as $userPath) {
Exemplo n.º 2
0
    $column['search']['order'] = $request->request->get('order', $column['search']['order']);
    $columns['columns'] = replaceFirstWith($columns['columns'], ['id' => $id], $column);
    saveJson($token, 'columns', $columns);
    return new Http\Response('', 200, ['Content-length' => 0]);
})->before($ensureIsUser);
$app->post('/columns/{id}/sources/', function ($id, Http\Request $request) use($app) {
    $token = $request->attributes->get('indieauth.client.token');
    $columns = loadJson($token, 'columns');
    $column = firstWith($columns['columns'], ['id' => $id]);
    $url = $request->request->get('url');
    if ($url === null) {
        return $app->abort(400, 'Provide a ‘url’ parameter to add to sources');
    }
    $url = Authentication\ensureUrlHasHttp($url);
    if ($request->request->get('mode', 'subscribe') === 'subscribe') {
        list($subscription, $err) = Subscriptions\subscribe($app, $url);
        if ($err !== null) {
            $app['logger']->warn('HTTP Error whilst trying to subscribe to a feed', ['feed URL' => $url, 'exception class' => get_class($err), 'message' => $err->getMessage()]);
            return $app->abort(500, "Subscribing to {$url} failed.");
        }
        // From the fetched feed index page, find a profile (if any) and build the source to add to the column definition.
        $mf = $subscription['resource']['mf2'];
        $profile = authorHCard($mf, $url);
        $source = ['topic' => $subscription['topic'], 'profile' => $profile];
        $found = false;
        foreach ($column['sources'] as $i => $s) {
            if ($s['topic'] == $source['topic']) {
                $found = true;
                // Update any profile details from re-subscribing.
                $column['sources'][$i] = $source;
                break;