1
0
mirror of https://github.com/moparisthebest/wallabag synced 2024-11-30 12:52:24 -05:00

remove duplicates by import, code changes: tabs replaced with spaces

This commit is contained in:
Maryana Rozhankivska 2014-04-08 11:41:06 +03:00
parent d7ee9f986b
commit 86da39886d

View File

@ -828,7 +828,7 @@ class Poche
define('IMPORT_LIMIT', 5); define('IMPORT_LIMIT', 5);
} }
if (!defined('IMPORT_DELAY')) { if (!defined('IMPORT_DELAY')) {
define('IMPORT_DELAY', 5); define('IMPORT_DELAY', 5);
} }
if ( isset($_FILES['file']) ) { if ( isset($_FILES['file']) ) {
@ -844,18 +844,18 @@ class Poche
$read = 0; $read = 0;
foreach (array('ol','ul') as $list) { foreach (array('ol','ul') as $list) {
foreach ($html->find($list) as $ul) { foreach ($html->find($list) as $ul) {
foreach ($ul->find('li') as $li) { foreach ($ul->find('li') as $li) {
$tmpEntry = array(); $tmpEntry = array();
$a = $li->find('a'); $a = $li->find('a');
$tmpEntry['url'] = $a[0]->href; $tmpEntry['url'] = $a[0]->href;
$tmpEntry['tags'] = $a[0]->tags; $tmpEntry['tags'] = $a[0]->tags;
$tmpEntry['is_read'] = $read; $tmpEntry['is_read'] = $read;
if ($tmpEntry['url']) { if ($tmpEntry['url']) {
$data[] = $tmpEntry; $data[] = $tmpEntry;
} }
} }
# the second <ol/ul> is for read links # the second <ol/ul> is for read links
$read = ((sizeof($data) && $read)?0:1); $read = ((sizeof($data) && $read)?0:1);
} }
} }
} }
@ -866,16 +866,16 @@ class Poche
$data[] = $record; $data[] = $record;
foreach ($record as $record2) { foreach ($record as $record2) {
if (is_array($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) { foreach ($data as $record) {
$url = trim( isset($record['article__url']) ? $record['article__url'] : (isset($record['url']) ? $record['url'] : '') ); $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 - ').'</a> <a href="./?import">'._('click to finish import').'</a><a>'); $title = (isset($record['title']) ? $record['title'] : _('Untitled - Import - ').'</a> <a href="./?import">'._('click to finish import').'</a><a>');
$body = (isset($record['content']) ? $record['content'] : ''); $body = (isset($record['content']) ? $record['content'] : '');
$isRead = (isset($record['is_read']) ? intval($record['is_read']) : (isset($record['archive'])?intval($record['archive']):0)); $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 //insert new record
$id = $this->store->add($url, $title, $body, $this->user->getId(), $isFavorite, $isRead); $id = $this->store->add($url, $title, $body, $this->user->getId(), $isFavorite, $isRead);
if ( $id ) { if ( $id ) {
//increment no of records inserted $urlsInserted[] = $url; //add
$i++;
if ( isset($record['tags']) && trim($record['tags']) ) { if ( isset($record['tags']) && trim($record['tags']) ) {
//@TODO: set tags //@TODO: set tags
} }
} }
} }
} }
$i = sizeof($urlsInserted);
if ( $i > 0 ) { if ( $i > 0 ) {
$this->messages->add('s', _('Articles inserted: ').$i._('. Please note, that some may be marked as "read".')); $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); $purifier = new HTMLPurifier($config);
foreach ($items as $item) { foreach ($items as $item) {
$url = new Url(base64_encode($item['url'])); $url = new Url(base64_encode($item['url']));
$content = Tools::getPageContent($url); $content = Tools::getPageContent($url);
$title = (($content['rss']['channel']['item']['title'] != '') ? $content['rss']['channel']['item']['title'] : _('Untitled')); $title = (($content['rss']['channel']['item']['title'] != '') ? $content['rss']['channel']['item']['title'] : _('Untitled'));
$body = (($content['rss']['channel']['item']['description'] != '') ? $content['rss']['channel']['item']['description'] : _('Undefined')); $body = (($content['rss']['channel']['item']['description'] != '') ? $content['rss']['channel']['item']['description'] : _('Undefined'));
//clean content to prevent xss attack //clean content to prevent xss attack
$title = $purifier->purify($title); $title = $purifier->purify($title);
$body = $purifier->purify($body); $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() public function export()
{ {
$filename = "wallabag-export-".$this->user->getId()."-".date("Y-m-d").".json"; $filename = "wallabag-export-".$this->user->getId()."-".date("Y-m-d").".json";
header('Content-Disposition: attachment; filename='.$filename); header('Content-Disposition: attachment; filename='.$filename);
$entries = $this->store->retrieveAll($this->user->getId()); $entries = $this->store->retrieveAll($this->user->getId());
echo $this->tpl->render('export.twig', array( echo $this->tpl->render('export.twig', array(
@ -978,13 +979,13 @@ class Poche
public function generateToken() public function generateToken()
{ {
if (ini_get('open_basedir') === '') { if (ini_get('open_basedir') === '') {
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
echo 'This is a server using Windows!'; echo 'This is a server using Windows!';
// alternative to /dev/urandom for Windows // alternative to /dev/urandom for Windows
$token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20); $token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20);
} else { } else {
$token = substr(base64_encode(file_get_contents('/dev/urandom', false, null, 0, 20)), 0, 15); $token = substr(base64_encode(file_get_contents('/dev/urandom', false, null, 0, 20)), 0, 15);
} }
} }
else { else {
$token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20); $token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20);