- 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);
- }
+ public function import() {
+
+ if (!defined('IMPORT_LIMIT')) {
+ define('IMPORT_LIMIT', 5);
+ }
+ if (!defined('IMPORT_DELAY')) {
+ define('IMPORT_DELAY', 5);
+ }
+
+ if ( isset($_FILES['file']) ) {
+ Tools::logm('Import stated: parsing file');
+
+ // assume, that file is in json format
+ $str_data = file_get_contents($_FILES['file']['tmp_name']);
+ $data = json_decode($str_data, true);
+
+ if ( $data === null ) {
+ //not json - assume html
+ $html = new simple_html_dom();
+ $html->load_file($_FILES['file']['tmp_name']);
+ $data = array();
+ $read = 0;
+ foreach (array('ol','ul') as $list) {
+ foreach ($html->find($list) as $ul) {
+ foreach ($ul->find('li') as $li) {
+ $tmpEntry = array();
+ $a = $li->find('a');
+ $tmpEntry['url'] = $a[0]->href;
+ $tmpEntry['tags'] = $a[0]->tags;
+ $tmpEntry['is_read'] = $read;
+ if ($tmpEntry['url']) {
+ $data[] = $tmpEntry;
+ }
+ }
+ # the second <ol/ul> is for read links
+ $read = ((sizeof($data) && $read)?0:1);