+ Tools::logm('Import of articles finished: '.$i.' articles added (w/o content if not provided).');
+ }
+ //file parsing finished here
+
+ //now download article contents if any
+
+ //check if we need to download any content
+ $recordsDownloadRequired = $this->store->retrieveUnfetchedEntriesCount($this->user->getId());
+ if ( $recordsDownloadRequired == 0 ) {
+ //nothing to download
+ $this->messages->add('s', _('Import finished.'));
+ Tools::logm('Import finished completely');
+ Tools::redirect();
+ }
+ else {
+ //if just inserted - don't download anything, download will start in next reload
+ if ( !isset($_FILES['file']) ) {
+ //download next batch
+ Tools::logm('Fetching next batch of articles...');
+ $items = $this->store->retrieveUnfetchedEntries($this->user->getId(), IMPORT_LIMIT);
+
+ $purifier = $this->getPurifier();
+
+ foreach ($items as $item) {
+ $url = new Url(base64_encode($item['url']));
+ Tools::logm('Fetching article '.$item['id']);
+ $content = Tools::getPageContent($url);
+
+ $title = (($content['rss']['channel']['item']['title'] != '') ? $content['rss']['channel']['item']['title'] : _('Untitled'));
+ $body = (($content['rss']['channel']['item']['description'] != '') ? $content['rss']['channel']['item']['description'] : _('Undefined'));
+
+ //clean content to prevent xss attack
+ $title = $purifier->purify($title);
+ $body = $purifier->purify($body);
+
+ $this->store->updateContentAndTitle($item['id'], $title, $body, $this->user->getId());
+ Tools::logm('Article '.$item['id'].' updated.');
+ }
+