From f86784c22d63ebd8315d0f86befa626779e36ff3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Sun, 6 Apr 2014 16:39:11 +0200 Subject: in RSS feed, add link to wallabag URL #556 --- inc/poche/Poche.class.php | 65 ++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 32 deletions(-) (limited to 'inc/poche/Poche.class.php') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index a662f695..a7bee65d 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -828,7 +828,7 @@ class Poche define('IMPORT_LIMIT', 5); } if (!defined('IMPORT_DELAY')) { - define('IMPORT_DELAY', 5); + define('IMPORT_DELAY', 5); } if ( isset($_FILES['file']) ) { @@ -844,18 +844,18 @@ class Poche $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
    is for read links - $read = ((sizeof($data) && $read)?0:1); + 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
      is for read links + $read = ((sizeof($data) && $read)?0:1); } } } @@ -866,7 +866,7 @@ class Poche $data[] = $record; foreach ($record as $record2) { if (is_array($record2)) { - $data[] = $record2; + $data[] = $record2; } } } @@ -886,7 +886,7 @@ class Poche //increment no of records inserted $i++; if ( isset($record['tags']) && trim($record['tags']) ) { - //@TODO: set tags + //@TODO: set tags } } @@ -919,17 +919,17 @@ class Poche $purifier = new HTMLPurifier($config); foreach ($items as $item) { - $url = new Url(base64_encode($item['url'])); - $content = Tools::getPageContent($url); + $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'] != '') ? $content['rss']['channel']['item']['description'] : _('Undefined')); + $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); + //clean content to prevent xss attack + $title = $purifier->purify($title); + $body = $purifier->purify($body); - $this->store->updateContentAndTitle($item['id'], $title, $body, $this->user->getId()); + $this->store->updateContentAndTitle($item['id'], $title, $body, $this->user->getId()); } } @@ -944,8 +944,8 @@ class Poche */ public function export() { - $filename = "wallabag-export-".$this->user->getId()."-".date("Y-m-d").".json"; - header('Content-Disposition: attachment; filename='.$filename); + $filename = "wallabag-export-".$this->user->getId()."-".date("Y-m-d").".json"; + header('Content-Disposition: attachment; filename='.$filename); $entries = $this->store->retrieveAll($this->user->getId()); echo $this->tpl->render('export.twig', array( @@ -978,13 +978,13 @@ class Poche public function generateToken() { if (ini_get('open_basedir') === '') { - if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { - echo 'This is a server using Windows!'; - // alternative to /dev/urandom for Windows - $token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20); - } else { - $token = substr(base64_encode(file_get_contents('/dev/urandom', false, null, 0, 20)), 0, 15); - } + if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { + echo 'This is a server using Windows!'; + // alternative to /dev/urandom for Windows + $token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20); + } else { + $token = substr(base64_encode(file_get_contents('/dev/urandom', false, null, 0, 20)), 0, 15); + } } else { $token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20); @@ -1031,6 +1031,7 @@ class Poche foreach ($entries as $entry) { $newItem = $feed->createNewItem(); $newItem->setTitle($entry['title']); + $newItem->setSource(Tools::getPocheUrl() . '?view=view&id=' . $entry['id']); $newItem->setLink($entry['url']); $newItem->setDate(time()); $newItem->setDescription($entry['content']); -- cgit v1.2.3 From 86da39886d11e6058199fc7da5adc24d1f84cb76 Mon Sep 17 00:00:00 2001 From: Maryana Rozhankivska Date: Tue, 8 Apr 2014 11:41:06 +0300 Subject: remove duplicates by import, code changes: tabs replaced with spaces --- inc/poche/Poche.class.php | 73 ++++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 36 deletions(-) (limited to 'inc/poche/Poche.class.php') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index a662f695..90fbcb2d 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -828,7 +828,7 @@ class Poche define('IMPORT_LIMIT', 5); } if (!defined('IMPORT_DELAY')) { - define('IMPORT_DELAY', 5); + define('IMPORT_DELAY', 5); } if ( isset($_FILES['file']) ) { @@ -844,18 +844,18 @@ class Poche $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
        is for read links - $read = ((sizeof($data) && $read)?0:1); + 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
          is for read links + $read = ((sizeof($data) && $read)?0:1); } } } @@ -866,16 +866,16 @@ class Poche $data[] = $record; foreach ($record as $record2) { if (is_array($record2)) { - $data[] = $record2; + $data[] = $record2; } } } } - $i = 0; //counter for articles inserted + $urlsInserted = array(); //urls of articles inserted foreach ($data as $record) { $url = trim( isset($record['article__url']) ? $record['article__url'] : (isset($record['url']) ? $record['url'] : '') ); - if ( $url ) { + if ( $url and !in_array($url, $urlsInserted) ) { $title = (isset($record['title']) ? $record['title'] : _('Untitled - Import - ').' '._('click to finish import').''); $body = (isset($record['content']) ? $record['content'] : ''); $isRead = (isset($record['is_read']) ? intval($record['is_read']) : (isset($record['archive'])?intval($record['archive']):0)); @@ -883,16 +883,17 @@ class Poche //insert new record $id = $this->store->add($url, $title, $body, $this->user->getId(), $isFavorite, $isRead); if ( $id ) { - //increment no of records inserted - $i++; + $urlsInserted[] = $url; //add + if ( isset($record['tags']) && trim($record['tags']) ) { - //@TODO: set tags + //@TODO: set tags } } } } + $i = sizeof($urlsInserted); if ( $i > 0 ) { $this->messages->add('s', _('Articles inserted: ').$i._('. Please note, that some may be marked as "read".')); } @@ -919,17 +920,17 @@ class Poche $purifier = new HTMLPurifier($config); foreach ($items as $item) { - $url = new Url(base64_encode($item['url'])); - $content = Tools::getPageContent($url); + $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'] != '') ? $content['rss']['channel']['item']['description'] : _('Undefined')); + $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); + //clean content to prevent xss attack + $title = $purifier->purify($title); + $body = $purifier->purify($body); - $this->store->updateContentAndTitle($item['id'], $title, $body, $this->user->getId()); + $this->store->updateContentAndTitle($item['id'], $title, $body, $this->user->getId()); } } @@ -944,8 +945,8 @@ class Poche */ public function export() { - $filename = "wallabag-export-".$this->user->getId()."-".date("Y-m-d").".json"; - header('Content-Disposition: attachment; filename='.$filename); + $filename = "wallabag-export-".$this->user->getId()."-".date("Y-m-d").".json"; + header('Content-Disposition: attachment; filename='.$filename); $entries = $this->store->retrieveAll($this->user->getId()); echo $this->tpl->render('export.twig', array( @@ -978,13 +979,13 @@ class Poche public function generateToken() { if (ini_get('open_basedir') === '') { - if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { - echo 'This is a server using Windows!'; - // alternative to /dev/urandom for Windows - $token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20); - } else { - $token = substr(base64_encode(file_get_contents('/dev/urandom', false, null, 0, 20)), 0, 15); - } + if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { + echo 'This is a server using Windows!'; + // alternative to /dev/urandom for Windows + $token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20); + } else { + $token = substr(base64_encode(file_get_contents('/dev/urandom', false, null, 0, 20)), 0, 15); + } } else { $token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20); -- cgit v1.2.3 From 5ce397847230c70c513ac4fbc3bfbb31498b443f Mon Sep 17 00:00:00 2001 From: Maryana Rozhankivska Date: Fri, 11 Apr 2014 14:43:17 +0300 Subject: logging by import added; error by creation table if exists in postgresql fixed. --- inc/poche/Poche.class.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'inc/poche/Poche.class.php') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 613377c6..3a4e78d6 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -832,6 +832,8 @@ class Poche } 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); @@ -897,6 +899,7 @@ class Poche if ( $i > 0 ) { $this->messages->add('s', _('Articles inserted: ').$i._('. Please note, that some may be marked as "read".')); } + Tools::logm('Import of articles finished: '.$i.' articles added (w/o content if not provided).'); } //file parsing finished here @@ -907,12 +910,14 @@ class Poche 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); $config = HTMLPurifier_Config::createDefault(); @@ -921,6 +926,7 @@ class Poche 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')); @@ -931,6 +937,7 @@ class Poche $body = $purifier->purify($body); $this->store->updateContentAndTitle($item['id'], $title, $body, $this->user->getId()); + Tools::logm('Article '.$item['id'].' updated.'); } } -- cgit v1.2.3 From 0f859c6f321af6dfaea66e04cde705ba97e6b5be Mon Sep 17 00:00:00 2001 From: Maryana Rozhankivska Date: Fri, 11 Apr 2014 17:21:54 +0300 Subject: error with empty content by import fixed. Also youtube and vimeo videos are allowd in content now. --- inc/poche/Poche.class.php | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'inc/poche/Poche.class.php') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 3a4e78d6..811895dc 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -373,9 +373,7 @@ class Poche $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); + $purifier = $this->getPurifier(); $title = $purifier->purify($title); $body = $purifier->purify($body); @@ -920,9 +918,7 @@ class Poche Tools::logm('Fetching next batch of articles...'); $items = $this->store->retrieveUnfetchedEntries($this->user->getId(), IMPORT_LIMIT); - $config = HTMLPurifier_Config::createDefault(); - $config->set('Cache.SerializerPath', CACHE); - $purifier = new HTMLPurifier($config); + $purifier = $this->getPurifier(); foreach ($items as $item) { $url = new Url(base64_encode($item['url'])); @@ -1064,4 +1060,16 @@ class Poche $this->messages->add('s', _('Cache deleted.')); Tools::redirect(); } + + /** + * return new purifier object with actual config + */ + protected function getPurifier() { + $config = HTMLPurifier_Config::createDefault(); + $config->set('Cache.SerializerPath', CACHE); + $config->set('HTML.SafeIframe', true); + $config->set('URI.SafeIframeRegexp', '%^(https?:)?//(www\.youtube(?:-nocookie)?\.com/embed/|player\.vimeo\.com/video/)%'); //allow YouTube and Vimeo$purifier = new HTMLPurifier($config); + + return new HTMLPurifier($config); + } } -- cgit v1.2.3