From a297fb1e38ce70a2c25f5dd9096fcfbf988ddf05 Mon Sep 17 00:00:00 2001 From: Maryana Rozhankivska Date: Thu, 3 Apr 2014 12:18:49 +0300 Subject: [PATCH] import w/o cron --- cron.php | 53 ------- inc/poche/Poche.class.php | 316 ++++++-------------------------------- 2 files changed, 46 insertions(+), 323 deletions(-) delete mode 100644 cron.php diff --git a/cron.php b/cron.php deleted file mode 100644 index 8fbf421a..00000000 --- a/cron.php +++ /dev/null @@ -1,53 +0,0 @@ -getConfigUser($user_id); - -if ($token != $config['token']) { - die(_('Uh, there is a problem with the cron.')); -} - -$items = $store->retrieveUnfetchedEntries($user_id, $limit); - -foreach ($items as $item) { - $url = new Url(base64_encode($item['url'])); - $content = Tools::getPageContent($url); - - $title = ($content['rss']['channel']['item']['title'] != '') ? $content['rss']['channel']['item']['title'] : _('Untitled'); - $body = $content['rss']['channel']['item']['description']; - - // // clean content from prevent xss attack - $config = HTMLPurifier_Config::createDefault(); - $purifier = new HTMLPurifier($config); - $title = $purifier->purify($title); - $body = $purifier->purify($body); - - - $store->updateContentAndTitle($item['id'], $title, $body, $user_id); -} \ No newline at end of file diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index ee3b2ac2..a662f695 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -368,31 +368,23 @@ class Poche switch ($action) { case 'add': - if (!$import) { - $content = Tools::getPageContent($url); - $title = ($content['rss']['channel']['item']['title'] != '') ? $content['rss']['channel']['item']['title'] : _('Untitled'); - $body = $content['rss']['channel']['item']['description']; - - // clean content from prevent xss attack - $config = HTMLPurifier_Config::createDefault(); - $config->set('Cache.SerializerPath', CACHE); - $purifier = new HTMLPurifier($config); - $title = $purifier->purify($title); - $body = $purifier->purify($body); - } - else { - $title = ''; - $body = ''; - } + $content = Tools::getPageContent($url); + $title = ($content['rss']['channel']['item']['title'] != '') ? $content['rss']['channel']['item']['title'] : _('Untitled'); + $body = $content['rss']['channel']['item']['description']; + + // clean content from prevent xss attack + $config = HTMLPurifier_Config::createDefault(); + $config->set('Cache.SerializerPath', CACHE); + $purifier = new HTMLPurifier($config); + $title = $purifier->purify($title); + $body = $purifier->purify($body); //search for possible duplicate $duplicate = NULL; - if (!$import) { - $duplicate = $this->store->retrieveOneByURL($url->getUrl(), $this->user->getId()); - } + $duplicate = $this->store->retrieveOneByURL($url->getUrl(), $this->user->getId()); $last_id = $this->store->add($url->getUrl(), $title, $body, $this->user->getId()); - if ( $last_id && !$import ) { + if ( $last_id ) { Tools::logm('add link ' . $url->getUrl()); if (DOWNLOAD_PICTURES) { $content = filtre_picture($body, $url->getUrl(), $last_id); @@ -416,18 +408,14 @@ class Poche $this->messages->add('s', _('the link has been added successfully')); } else { - if (!$import) { - $this->messages->add('e', _('error during insertion : the link wasn\'t added')); - Tools::logm('error during insertion : the link wasn\'t added ' . $url->getUrl()); - } + $this->messages->add('e', _('error during insertion : the link wasn\'t added')); + Tools::logm('error during insertion : the link wasn\'t added ' . $url->getUrl()); } - if (!$import) { - if ($autoclose == TRUE) { - Tools::redirect('?view=home'); - } else { - Tools::redirect('?view=home&closewin=true'); - } + if ($autoclose == TRUE) { + Tools::redirect('?view=home'); + } else { + Tools::redirect('?view=home&closewin=true'); } break; case 'delete': @@ -448,33 +436,21 @@ class Poche case 'toggle_fav' : $this->store->favoriteById($id, $this->user->getId()); Tools::logm('mark as favorite link #' . $id); - if (!$import) { - Tools::redirect(); - } + Tools::redirect(); break; case 'toggle_archive' : $this->store->archiveById($id, $this->user->getId()); Tools::logm('archive link #' . $id); - if (!$import) { - Tools::redirect(); - } + Tools::redirect(); break; case 'archive_all' : $this->store->archiveAll($this->user->getId()); Tools::logm('archive all links'); - if (!$import) { - Tools::redirect(); - } + Tools::redirect(); break; case 'add_tag' : - if($import){ - $entry_id = $id; - $tags = explode(',', $tags); - } - else{ - $tags = explode(',', $_POST['value']); - $entry_id = $_POST['entry_id']; - } + $tags = explode(',', $_POST['value']); + $entry_id = $_POST['entry_id']; $entry = $this->store->retrieveOneById($entry_id, $this->user->getId()); if (!$entry) { $this->messages->add('e', _('Article not found!')); @@ -509,9 +485,7 @@ class Poche $this->store->setTagToEntry($tag_id, $entry_id); } } - if(!$import) { - Tools::redirect(); - } + Tools::redirect(); break; case 'remove_tag' : $tag_id = $_GET['tag_id']; @@ -844,206 +818,19 @@ class Poche Tools::redirect(); } - /** - * 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
    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