- $unlink = unlink($targetFile);
- $this->messages->add('s', _('import from pocket completed. You have to execute the cron to fetch content.'));
- Tools::logm('import from pocket completed');
- Tools::redirect();
- }
-
- /**
- * import from Readability. poche needs a ./readability file
- * @todo add the return value
- * @param string $targetFile the file used for importing
- * @return boolean
- */
- private function importFromReadability($targetFile)
- {
- # TODO gestion des articles lus / favs
- $str_data = file_get_contents($targetFile);
- $data = json_decode($str_data,true);
- Tools::logm('starting import from Readability');
- $count = 0;
- foreach ($data as $key => $value) {
- $url = NULL;
- $favorite = FALSE;
- $archive = FALSE;
- foreach ($value as $item) {
- foreach ($item as $attr => $value) {
- if ($attr == 'article__url') {
- $url = new Url(base64_encode($value));
- }
- $sequence = '';
- if (STORAGE == 'postgres') {
- $sequence = 'entries_id_seq';
- }
- if ($value == 'true') {
- if ($attr == 'favorite') {
- $favorite = TRUE;
- }
- if ($attr == 'archive') {
- $archive = TRUE;
- }
- }
- }
-
- # we can add the url
- if (!is_null($url) && $url->isCorrect()) {
- $this->action('add', $url, 0, TRUE);
- $count++;
- if ($favorite) {
- $last_id = $this->store->getLastId($sequence);
- $this->action('toggle_fav', $url, $last_id, TRUE);
- }
- if ($archive) {
- $last_id = $this->store->getLastId($sequence);
- $this->action('toggle_archive', $url, $last_id, TRUE);
- }
- }
+ $i = 0; //counter for articles inserted
+ foreach ($data as $record) {
+ $url = trim( isset($record['article__url']) ? $record['article__url'] : (isset($record['url']) ? $record['url'] : '') );
+ if ( $url ) {
+ $title = (isset($record['title']) ? $record['title'] : _('Untitled - Import - ').'</a> <a href="./?import">'._('click to finish import').'</a><a>');
+ $body = (isset($record['content']) ? $record['content'] : '');
+ $isRead = (isset($record['is_read']) ? intval($record['is_read']) : (isset($record['archive'])?intval($record['archive']):0));
+ $isFavorite = (isset($record['is_fav']) ? intval($record['is_fav']) : (isset($record['favorite'])?intval($record['favorite']):0) );
+ //insert new record
+ $id = $this->store->add($url, $title, $body, $this->user->getId(), $isFavorite, $isRead);
+ if ( $id ) {
+ //increment no of records inserted
+ $i++;
+ if ( isset($record['tags']) && trim($record['tags']) ) {
+ //@TODO: set tags
+
+ }