1
0
mirror of https://github.com/moparisthebest/wallabag synced 2024-11-23 17:42:15 -05:00

merge fix 776

This commit is contained in:
Thomas Citharel 2014-08-16 00:54:46 +02:00
commit 1daa8e4a0f
3 changed files with 35 additions and 36 deletions

View File

@ -551,42 +551,39 @@ class Poche
* import datas into your wallabag * import datas into your wallabag
* @return boolean * @return boolean
*/ */
public function import()
{
if (isset($_FILES['file'])) {
Tools::logm('Import stated: parsing file');
// assume, that file is in json format public function import() {
$str_data = file_get_contents($_FILES['file']['tmp_name']); if ( isset($_FILES['file']) && $_FILES['file']['tmp_name'] ) {
$data = json_decode($str_data, true); Tools::logm('Import stated: parsing file');
if ($data === null) {
// not json - assume html // assume, that file is in json format
$str_data = file_get_contents($_FILES['file']['tmp_name']);
$data = json_decode($str_data, true);
$html = new simple_html_dom(); if ( $data === null ) {
$html->load_file($_FILES['file']['tmp_name']); //not json - assume html
$data = array(); $html = new simple_html_dom();
$read = 0; $html->load_file($_FILES['file']['tmp_name']);
foreach(array('ol','ul') as $list) { $data = array();
foreach($html->find($list) as $ul) { $read = 0;
foreach($ul->find('li') as $li) { foreach (array('ol','ul') as $list) {
$tmpEntry = array(); foreach ($html->find($list) as $ul) {
$a = $li->find('a'); foreach ($ul->find('li') as $li) {
$tmpEntry['url'] = $a[0]->href; $tmpEntry = array();
$tmpEntry['tags'] = $a[0]->tags; $a = $li->find('a');
$tmpEntry['is_read'] = $read; $tmpEntry['url'] = $a[0]->href;
if ($tmpEntry['url']) { $tmpEntry['tags'] = $a[0]->tags;
$data[] = $tmpEntry; $tmpEntry['is_read'] = $read;
} if ($tmpEntry['url']) {
} $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);
}
}
} }
}
}
// for readability structure // for readability structure
@ -629,9 +626,11 @@ class Poche
$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".'));
} }
Tools::logm('Import of articles finished: ' . $i . ' articles added (w/o content if not provided).'); Tools::logm('Import of articles finished: '.$i.' articles added (w/o content if not provided).');
} }
else {
$this->messages->add('s', _('Did you forget to select a file?'));
}
// file parsing finished here // file parsing finished here
// now download article contents if any // now download article contents if any
// check if we need to download any content // check if we need to download any content

View File

@ -111,7 +111,7 @@
<fieldset class="w500p"> <fieldset class="w500p">
<div class="row"> <div class="row">
<label class="col w150p" for="file">{% trans "File:" %}</label> <label class="col w150p" for="file">{% trans "File:" %}</label>
<input class="col" type="file" id="file" name="file" tabindex="4"> <input class="col" type="file" id="file" name="file" tabindex="4" required="required">
</div> </div>
<div class="row mts txtcenter"> <div class="row mts txtcenter">
<button class="bouton" type="submit" tabindex="4">{% trans "Import" %}</button> <button class="bouton" type="submit" tabindex="4">{% trans "Import" %}</button>

View File

@ -110,7 +110,7 @@
<fieldset class="w500p"> <fieldset class="w500p">
<div class="row"> <div class="row">
<label class="col w150p" for="file">{% trans "File:" %}</label> <label class="col w150p" for="file">{% trans "File:" %}</label>
<input class="col" type="file" id="file" name="file" tabindex="4"> <input class="col" type="file" id="file" name="file" tabindex="4" required="required">
</div> </div>
<div class="row mts txtcenter"> <div class="row mts txtcenter">
<button class="bouton" type="submit" tabindex="4">{% trans "Import" %}</button> <button class="bouton" type="submit" tabindex="4">{% trans "Import" %}</button>