]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
[add] upload form for import
authorNicolas Lœuillet <nicolas.loeuillet@gmail.com>
Fri, 28 Feb 2014 19:36:32 +0000 (20:36 +0100)
committerNicolas Lœuillet <nicolas.loeuillet@gmail.com>
Fri, 28 Feb 2014 19:36:32 +0000 (20:36 +0100)
inc/poche/Poche.class.php
inc/poche/Tools.class.php
index.php
themes/baggy/config.twig

index 49651c5290ffd45112d5e26f3a91257868936e20..026b0b4e1240e9efe30595bdc7434f8ed790fbe7 100755 (executable)
@@ -1068,13 +1068,7 @@ class Poche
             Tools::redirect();
         }
         
-        $targetDefinition = 'IMPORT_' . 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();
-        }
+        $targetFile = CACHE . '/' . constant(strtoupper($from) . '_FILE');
         
         if (! file_exists($targetFile)) {
             $this->messages->add('e', _('Could not find required "' . $targetFile . '" import file.'));
@@ -1084,6 +1078,22 @@ class Poche
         $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
      * @return json all poche entries
index 4ed28ed1b07a925991feeef349c498369c79cd9b..eed7afbdda3234341339a3ffa346a5c6bc93a610 100644 (file)
@@ -241,7 +241,6 @@ class Tools
         }
     }
 
-
     public static function download_db() {
         header('Content-Disposition: attachment; filename="poche.sqlite.gz"');
         self::status(200);
index 9f5d0adeef47ae56fb1eefe6b241457d78912d52..ecae911983ef77f92312a149037b0fae5e4f69fe 100644 (file)
--- a/index.php
+++ b/index.php
@@ -75,6 +75,8 @@ if (isset($_GET['login'])) {
     $poche->updateTheme();
 } elseif (isset($_GET['updatelanguage'])) {
     $poche->updateLanguage();
+} elseif (isset($_GET['uploadfile'])) {
+    $poche->uploadFile();
 } elseif (isset($_GET['feed'])) {
     if (isset($_GET['action']) && $_GET['action'] == 'generate') {
         $poche->generateToken();
index b37ac115a9e4d131a3bc102b57e3edaeda92e0fb..4026bf28a23b62aae06f5ac51941c959696fe8f1 100644 (file)
             {% endif %}
 
             <h2>{% trans "Import" %}</h2>
-            <p>{% trans "Please execute the import script locally as it can take a very long time." %}</p>
-            <p>{% trans "More info in the official documentation:" %} <a href="http://doc.wallabag.org/doku.php?id=users:migrate">wallabag.org</a></p>
+            <p>1. {% trans "Select a file on your computer and upload it." %}</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>
-                <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=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=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=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=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> {{ '(after uploaded %s file)'|trans|format(constant('READABILITY_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> {{ '(after uploaded %s file)'|trans|format(constant('POCHE_FILE')) }}</li>
             </ul>
 
             <h2>{% trans "Export your wallabag data" %}</h2>