public function testValidate() { $source = new Source($this->db->getInstance()); $result = $source->validate(array('id' => 1, 'name' => "Adam Bien<script>alert('test')</script>", 'period' => 'daily', 'created_at' => date('Y-m-d H:i:s'), 'test' => 'xyz')); $this->assertArrayHasKey('created_at', $result); $this->assertArrayHasKey('period', $result); $this->assertArrayNotHasKey('test', $result); $this->assertEquals('daily', $result['period']); $this->assertEquals('Adam Bien', $result['name']); }
public function getRepository(AbstractConnection $connection = null) { if ($this->repository == null) { if ($connection == null) { $connection = $this->app->db; } $this->repository = new SourceRepository($connection); $this->repository->setUserScope($this->app->user['id']); } return $this->repository; }
/** * @param array $source * @return array */ protected function fetchSource(array $source) { $fetcher = new Fetcher(); $fetcher->setClient(new Client()); $fetcher->setTimeout($this->app->config('fetcher.timeout')); $content = $fetcher->get($source['uri']); if (!empty($content)) { $defaultWorkerClass = $this->app->config('worker.default'); /** * @var $worker \Nogo\Feedbox\Feed\Worker */ $worker = new $defaultWorkerClass(); $worker->setSanitizer($this->sanitizer); $worker->setContent($content); try { $items = $worker->execute(); } catch (\Exception $e) { $items = null; } if ($items != null) { foreach ($items as $item) { if (isset($item['uid'])) { $dbItem = $this->itemRepository->findBy('uid', $item['uid']); if (!empty($dbItem)) { if ($item['content'] !== $dbItem['content'] || $item['title'] !== $dbItem['title']) { $item['id'] = $dbItem['id']; $item['starred'] = $dbItem['starred']; $item['created_at'] = $dbItem['created_at']; } else { continue; } } } $item['source_id'] = $source['id']; $this->itemRepository->persist($item); } } $source['last_update'] = date('Y-m-d H:i:s'); if (empty($source['period'])) { $source['period'] = $worker->getUpdateInterval(); } $source['errors'] = $worker->getErrors(); } else { $source['errors'] = $fetcher->getError(); } $source['unread'] = $this->itemRepository->countSourceUnread([$source['id']]); $this->sourceRepository->persist($source); // update tag unread counter if (!empty($source['tag_id'])) { $tag = $this->tagRepository->find($source['tag_id']); if ($tag) { $tag['unread'] = $this->sourceRepository->countTagUnread([$tag['id']]); $this->tagRepository->persist($tag); } } // clean up double uids in this source $uids = $this->itemRepository->findDoubleUid($source['id']); foreach ($uids as $uid) { $items = $this->itemRepository->findAllBy('uid', $uid); for ($i = 1; $i < count($items); $i++) { $this->itemRepository->remove($items[$i]['id']); } } return $source; }
use Nogo\Feedbox\Feed\Fetcher; use Nogo\Feedbox\Helper\ConfigLoader; use Nogo\Feedbox\Helper\DatabaseConnector; use Nogo\Feedbox\Repository\Item; use Nogo\Feedbox\Repository\Source; use Nogo\Feedbox\Repository\Tag; define('ROOT_DIR', dirname(__FILE__)); require ROOT_DIR . '/vendor/autoload.php'; // load API config $configLoader = new ConfigLoader(ROOT_DIR . '/src/Nogo/Feedbox/Resources/config/default.yml', ROOT_DIR . '/data/config.yml'); $config = $configLoader->getConfig(); // database connection with pdo $connector = new DatabaseConnector($config['database_adapter'], $config['database_dsn'], $config['database_username'], $config['database_password']); $connection = $connector->getInstance(); // create repositories $sourceRepository = new Source($connection); $tagRepository = new Tag($connection); $itemRepository = new Item($connection); // fetch active sources with uri $sources = $sourceRepository->findAllActiveWithUri(); // get the feed runner $defaultWorkerClass = $config['worker.default']; $sanitizer = new \Nogo\Feedbox\Helper\HtmlPurifierSanitizer(); $fetcher = new Fetcher(); $fetcher->setClient(new Client()); $fetcher->setTimeout($config['fetcher.timeout']); $now = new \DateTime(); $user_id = null; foreach ($sources as $source) { $error = false; if (!empty($source['uri'])) {
break; } $connector = new DatabaseConnector($app->config('database_adapter'), $app->config('database_dsn'), $app->config('database_username'), $app->config('database_password')); $db = $connector->getInstance(); if ($db != null) { $connector->migrate($db, ROOT_DIR . '/src/Nogo/Feedbox/Resources/sql/' . $app->config('database_adapter')); $user = array('name' => $input['login_username'], 'email' => $input['login_email'], 'password' => password_hash($input['login_password'], PASSWORD_DEFAULT), 'active' => true, 'superadmin' => true, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')); $userRepository = new User($db); $user['id'] = $userRepository->persist($user); $opml = trim($request->post('opml')); if (!empty($opml)) { $opmlLoader = new OpmlLoader(); $opmlLoader->setContent($opml); $sources = $opmlLoader->run(); if (!empty($sources)) { $sourceRepository = new Source($db); foreach ($sources as $source) { $source['user_id'] = $user['id']; $sourceRepository->persist($source); } } } } $app->render('done.html.twig', array('title' => 'Install')); $app->config('installed', true); } }); } $app->get('/migrate', function () use($app) { $connector = new DatabaseConnector($app->config('database_adapter'), $app->config('database_dsn'), $app->config('database_username'), $app->config('database_password')); $db = $connector->getInstance();