- * import from Instapaper. poche needs a ./instapaper-export.html file
- * @todo add the return value
- * @param string $targetFile the file used for importing
- * @return boolean
- */
- private function importFromInstapaper($targetFile)
- {
- # TODO gestion des articles favs
- $html = new simple_html_dom();
- $html->load_file($targetFile);
- Tools::logm('starting import from instapaper');
-
- $read = 0;
- $errors = array();
- foreach($html->find('ol') as $ul)
- {
- foreach($ul->find('li') as $li)
- {
- $a = $li->find('a');
- $url = new Url(base64_encode($a[0]->href));
- $this->action('add', $url, 0, TRUE);
- if ($read == '1') {
- $sequence = '';
- if (STORAGE == 'postgres') {
- $sequence = 'entries_id_seq';
- }
- $last_id = $this->store->getLastId($sequence);
- $this->action('toggle_archive', $url, $last_id, TRUE);
- }
- }
-
- # the second <ol> is for read links
- $read = 1;
- }
-
- $unlink = unlink($targetFile);
- $this->messages->add('s', _('import from instapaper completed. You have to execute the cron to fetch content.'));
- Tools::logm('import from instapaper completed');
- Tools::redirect();
- }
-
- /**
- * import from Pocket. poche needs a ./ril_export.html file
- * @todo add the return value
- * @param string $targetFile the file used for importing
- * @return boolean
- */
- private function importFromPocket($targetFile)
- {
- # TODO gestion des articles favs
- $html = new simple_html_dom();
- $html->load_file($targetFile);
- Tools::logm('starting import from pocket');
-
- $read = 0;
- $errors = array();
- foreach($html->find('ul') as $ul)
- {
- foreach($ul->find('li') as $li)
- {
- $a = $li->find('a');
- $url = new Url(base64_encode($a[0]->href));
- $this->action('add', $url, 0, TRUE);
- $sequence = '';
- if (STORAGE == 'postgres') {
- $sequence = 'entries_id_seq';
- }
- $last_id = $this->store->getLastId($sequence);
- if ($read == '1') {
- $this->action('toggle_archive', $url, $last_id, TRUE);
- }
- $tags = $a[0]->tags;
- if(!empty($tags)) {
- $this->action('add_tag',$url,$last_id,true,false,$tags);
- }
- }
-
- # the second <ul> is for read links
- $read = 1;
- }
-
- $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);
- }
- }
- }
- }
-
- unlink($targetFile);
- $this->messages->add('s', _('import from Readability completed. You have to execute the cron to fetch content.'));
- Tools::logm('import from Readability completed');
- Tools::redirect();
- }
-
- /**
- * import from Poche exported file
- * @param string $targetFile the file used for importing