Exemple #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $nomail = $input->getOption('nomail');
     $skipErrors = $input->getOption('skip-errors');
     $dry = $input->getOption('dry');
     $all = $input->getOption('all');
     $single = $input->getOption('single');
     if ($all && $single) {
         throw new RuntimeException('Cannot set --all and --single together.');
     }
     if (!$all && !$single) {
         throw new RuntimeException('Specify either --all or --single.');
     }
     $feeds = [];
     if ($single) {
         $feeds = FeedQuery::create()->findById($single);
     } else {
         $feeds = FeedQuery::create()->find();
     }
     foreach ($feeds as $feed) {
         try {
             $newItems = $feed->queryItems();
             $oldCount = $feed->countItems();
             $newCount = count($newItems);
             $newDateSet = false;
             for ($i = $newCount - 1; $i >= $oldCount; $i--) {
                 $feed->addItem($newItems[$i]);
                 if (!$newDateSet) {
                     $feed->setUpdatedDate($newItems[$i]->getPublishedDate());
                     $newDateSet = true;
                 }
                 print "Adding " . $newItems[$i]->getTitle() . "\n";
             }
             if (!$dry) {
                 print "Saving " . $feed->getTitle() . "\n";
                 $feed->save();
             } else {
                 print "Dry run, no saving\n";
             }
         } catch (Exception $ex) {
             if ($skipErrors) {
                 print "Error: " . $ex->getMessage() . "\n";
             } else {
                 throw $ex;
             }
         }
     }
 }
Exemple #2
0
    } else {
        $app->render('error.php', array('errorMessage' => 'An unexpected error occured.'), 500);
    }
});
// Main endpoint for the feed readers
$app->get('/feeds/:id', function ($id) use($app) {
    $feed = FeedQuery::create()->findPk($id);
    if ($feed == null) {
        throw new PageNotFoundException();
    }
    $items = ItemQuery::create()->filterByFeed($feed)->orderByPublishedDate(\Propel\Runtime\ActiveQuery\Criteria::DESC)->limit(20)->find();
    $app->render('atom.php', array('feed' => $feed, 'items' => $items));
})->name('feed');
$app->post('/feeds', function () use($app) {
    $rootUrl = $app->urlFor('root') . '?apikey=' . $GLOBALS['config']['apikey'];
    $url = $app->request->post('url');
    print 'Submitted url ' . $url;
    if (empty($url)) {
        return;
    }
    $parser = \Level14\Website2Feed\Model\Parsers\ParserLoader::getParser($url);
    $feed = $parser->parseMetadata();
    $feed->save();
    $app->redirect($rootUrl);
})->name('newfeed');
// Main endpoint for users, list feeds
$app->get('/', function () use($app) {
    $feeds = FeedQuery::create()->find();
    $app->render('listFeeds.php', array('feeds' => $feeds));
})->name('root');
$app->run();