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

[add] upload form for import

This commit is contained in:
Nicolas Lœuillet 2014-02-28 20:36:32 +01:00
parent 4c14936353
commit 31a10069a5
4 changed files with 38 additions and 14 deletions

View File

@ -1068,13 +1068,7 @@ class Poche
Tools::redirect(); Tools::redirect();
} }
$targetDefinition = 'IMPORT_' . strtoupper($from) . '_FILE'; $targetFile = CACHE . '/' . constant(strtoupper($from) . '_FILE');
$targetFile = constant($targetDefinition);
if (! defined($targetDefinition)) {
$this->messages->add('e', _('Incomplete inc/poche/define.inc.php file, please define "' . $targetDefinition . '".'));
Tools::redirect();
}
if (! file_exists($targetFile)) { if (! file_exists($targetFile)) {
$this->messages->add('e', _('Could not find required "' . $targetFile . '" import file.')); $this->messages->add('e', _('Could not find required "' . $targetFile . '" import file.'));
@ -1084,6 +1078,22 @@ class Poche
$this->$providers[$from]($targetFile); $this->$providers[$from]($targetFile);
} }
public function uploadFile() {
if(isset($_FILES['file']))
{
$dir = CACHE . '/';
$file = basename($_FILES['file']['name']);
if(move_uploaded_file($_FILES['file']['tmp_name'], $dir . $file)) {
$this->messages->add('s', _('File uploaded. You can now execute import.'));
}
else {
$this->messages->add('e', _('Error while importing file. Do you have access to upload it?'));
}
}
Tools::redirect('?view=config');
}
/** /**
* export poche entries in json * export poche entries in json
* @return json all poche entries * @return json all poche entries

View File

@ -241,7 +241,6 @@ class Tools
} }
} }
public static function download_db() { public static function download_db() {
header('Content-Disposition: attachment; filename="poche.sqlite.gz"'); header('Content-Disposition: attachment; filename="poche.sqlite.gz"');
self::status(200); self::status(200);

View File

@ -75,6 +75,8 @@ if (isset($_GET['login'])) {
$poche->updateTheme(); $poche->updateTheme();
} elseif (isset($_GET['updatelanguage'])) { } elseif (isset($_GET['updatelanguage'])) {
$poche->updateLanguage(); $poche->updateLanguage();
} elseif (isset($_GET['uploadfile'])) {
$poche->uploadFile();
} elseif (isset($_GET['feed'])) { } elseif (isset($_GET['feed'])) {
if (isset($_GET['action']) && $_GET['action'] == 'generate') { if (isset($_GET['action']) && $_GET['action'] == 'generate') {
$poche->generateToken(); $poche->generateToken();

View File

@ -103,13 +103,26 @@
{% endif %} {% endif %}
<h2>{% trans "Import" %}</h2> <h2>{% trans "Import" %}</h2>
<p>{% trans "Please execute the import script locally as it can take a very long time." %}</p> <p>1. {% trans "Select a file on your computer and upload it." %}</p>
<p>{% trans "More info in the official documentation:" %} <a href="http://doc.wallabag.org/doku.php?id=users:migrate">wallabag.org</a></p> <form method="post" action="?uploadfile" name="uploadfile" enctype="multipart/form-data">
<fieldset class="w500p">
<div class="row">
<label class="col w150p" for="file">{% trans "File:" %}</label>
<input class="col" type="file" id="file" name="file" tabindex="4">
</div>
<div class="row mts txtcenter">
<button class="bouton" type="submit" tabindex="4">{% trans "Upload" %}</button>
</div>
</fieldset>
<input type="hidden" name="MAX_FILE_SIZE" value="1048576">
<input type="hidden" name="returnurl" value="{{ referer }}">
</form>
<p>2. {% trans "Then, click on the right link below." %}</p>
<ul> <ul>
<li><a href="./?import&amp;from=pocket">{% trans "Import from Pocket" %}</a> {{ '(you must have a %s file on your server)'|trans|format(constant('POCKET_FILE')) }}</li> <li><a href="./?import&amp;from=pocket">{% trans "Import from Pocket" %}</a> {{ '(after uploaded %s file)'|trans|format(constant('POCKET_FILE')) }}</li>
<li><a href="./?import&amp;from=readability">{% trans "Import from Readability" %}</a> {{ '(you must have a %s file on your server)'|trans|format(constant('READABILITY_FILE')) }}</li> <li><a href="./?import&amp;from=readability">{% trans "Import from Readability" %}</a> {{ '(after uploaded %s file)'|trans|format(constant('READABILITY_FILE')) }}</li>
<li><a href="./?import&amp;from=instapaper">{% trans "Import from Instapaper" %}</a> {{ '(you must have a %s file on your server)'|trans|format(constant('INSTAPAPER_FILE')) }}</li> <li><a href="./?import&amp;from=instapaper">{% trans "Import from Instapaper" %}</a> {{ '(after uploaded %s file)'|trans|format(constant('INSTAPAPER_FILE')) }}</li>
<li><a href="./?import&amp;from=poche">{% trans "Import from wallabag" %}</a> {{ '(you must have a %s file on your server)'|trans|format(constant('POCHE_FILE')) }}</li> <li><a href="./?import&amp;from=poche">{% trans "Import from wallabag" %}</a> {{ '(after uploaded %s file)'|trans|format(constant('POCHE_FILE')) }}</li>
</ul> </ul>
<h2>{% trans "Export your wallabag data" %}</h2> <h2>{% trans "Export your wallabag data" %}</h2>