]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Merge pull request #532 from wallabag/upload-file
authorNicolas Lœuillet <nicolas@loeuillet.org>
Fri, 7 Mar 2014 12:26:56 +0000 (13:26 +0100)
committerNicolas Lœuillet <nicolas@loeuillet.org>
Fri, 7 Mar 2014 12:26:56 +0000 (13:26 +0100)
New import system

1  2 
inc/poche/Poche.class.php
index.php
themes/baggy/config.twig

index ba262c98ec1bb329f0f63b1d490419d6e7778ff7,5a89a8d27fa0657a2aecbef5073e0cd52d9e0d23..fb4e1a7fed98114d8b9004538c5f52ad658a6b24
@@@ -362,60 -362,6 +362,6 @@@ class Poch
          );
      }
  
-     protected function getPageContent(Url $url)
-     {
-         // Saving and clearing context
-         $REAL = array();
-         foreach( $GLOBALS as $key => $value ) {
-             if( $key != 'GLOBALS' && $key != '_SESSION' && $key != 'HTTP_SESSION_VARS' ) {
-                 $GLOBALS[$key] = array();
-                 $REAL[$key] = $value;
-             }
-         }
-         // Saving and clearing session
-         $REAL_SESSION = array();
-         foreach( $_SESSION as $key => $value ) {
-             $REAL_SESSION[$key] = $value;
-             unset($_SESSION[$key]);
-         }
-         // Running code in different context
-         $scope = function() {
-             extract( func_get_arg(1) );
-             $_GET = $_REQUEST = array(
-                         "url" => $url->getUrl(),
-                         "max" => 5,
-                         "links" => "preserve",
-                         "exc" => "",
-                         "format" => "json",
-                         "submit" => "Create Feed"
-             );
-             ob_start();
-             require func_get_arg(0);
-             $json = ob_get_flush();
-             return $json;
-         };
-         $json = $scope( "inc/3rdparty/makefulltextfeed.php", array("url" => $url) );
-         // Clearing and restoring context
-         foreach( $GLOBALS as $key => $value ) {
-             if( $key != "GLOBALS" && $key != "_SESSION" ) {
-                 unset($GLOBALS[$key]);
-             }
-         }
-         foreach( $REAL as $key => $value ) {
-             $GLOBALS[$key] = $value;
-         }
-         // Clearing and restoring session
-         foreach( $_SESSION as $key => $value ) {
-             unset($_SESSION[$key]);
-         }
-         foreach( $REAL_SESSION as $key => $value ) {
-             $_SESSION[$key] = $value;
-         }
-         return json_decode($json, true);
-     }
      /**
       * Call action (mark as fav, archive, delete, etc.)
       */
          switch ($action)
          {
              case 'add':
-                 $content = $this->getPageContent($url);
-                 $title = ($content['rss']['channel']['item']['title'] != '') ? $content['rss']['channel']['item']['title'] : _('Untitled');
-                 $body = $content['rss']['channel']['item']['description'];
-                 // clean content from prevent xss attack
-                 $config = HTMLPurifier_Config::createDefault();
-                 $purifier = new HTMLPurifier($config);
-                 $title = $purifier->purify($title);
-                 $body = $purifier->purify($body);
+                 if (!$import) {
+                     $content = Tools::getPageContent($url);
+                     $title = ($content['rss']['channel']['item']['title'] != '') ? $content['rss']['channel']['item']['title'] : _('Untitled');
+                     $body = $content['rss']['channel']['item']['description'];
+                     // clean content from prevent xss attack
+                     $config = HTMLPurifier_Config::createDefault();
+                     $purifier = new HTMLPurifier($config);
+                     $title = $purifier->purify($title);
+                     $body = $purifier->purify($body);
+                 }
+                 else {
+                     $title = '';
+                     $body = '';
+                 }
  
                  //search for possible duplicate if not in import mode
                  if (!$import) {
          switch ($view)
          {
              case 'config':
 -                $dev = trim($this->getPocheVersion('dev'));
 -                $prod = trim($this->getPocheVersion('prod'));
 +                $dev_infos = $this->getPocheVersion('dev');
 +                $dev = trim($dev_infos[0]);
 +                $check_time_dev = date('d-M-Y H:i', $dev_infos[1]);
 +                $prod_infos = $this->getPocheVersion('prod');
 +                $prod = trim($prod_infos[0]);
 +                $check_time_prod = date('d-M-Y H:i', $prod_infos[1]);
                  $compare_dev = version_compare(POCHE, $dev);
                  $compare_prod = version_compare(POCHE, $prod);
                  $themes = $this->getInstalledThemes();
                      'languages' => $languages,
                      'dev' => $dev,
                      'prod' => $prod,
 +                    'check_time_dev' => $check_time_dev,
 +                    'check_time_prod' => $check_time_prod,
                      'compare_dev' => $compare_dev,
                      'compare_prod' => $compare_prod,
                      'token' => $token,
              # the second <ol> is for read links
              $read = 1;
          }
-         $this->messages->add('s', _('import from instapaper completed'));
+         $this->messages->add('s', _('import from instapaper completed. You have to execute the cron to fetch content.'));
          Tools::logm('import from instapaper completed');
          Tools::redirect();
      }
              # the second <ul> is for read links
              $read = 1;
          }
-         $this->messages->add('s', _('import from pocket completed'));
+         $this->messages->add('s', _('import from pocket completed. You have to execute the cron to fetch content.'));
          Tools::logm('import from pocket completed');
          Tools::redirect();
      }
                  }
              }
          }
-         $this->messages->add('s', _('import from Readability completed. ' . $count . ' new links.'));
+         $this->messages->add('s', _('import from Readability completed. You have to execute the cron to fetch content.'));
          Tools::logm('import from Readability completed');
          Tools::redirect();
      }
              }
              
          }
-         $this->messages->add('s', _('import from Poche completed. ' . $count . ' new links.'));
+         $this->messages->add('s', _('import from Poche completed. You have to execute the cron to fetch content.'));
          Tools::logm('import from Poche completed');
          Tools::redirect();
      }
              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.'));
          $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
      private function getPocheVersion($which = 'prod')
      {
          $cache_file = CACHE . '/' . $which;
 +        $check_time = time();
  
          # checks if the cached version file exists
          if (file_exists($cache_file) && (filemtime($cache_file) > (time() - 86400 ))) {
             $version = file_get_contents($cache_file);
 +           $check_time = filemtime($cache_file);
          } else {
             $version = file_get_contents('http://static.wallabag.org/versions/' . $which);
             file_put_contents($cache_file, $version, LOCK_EX);
          }
 -        return $version;
 +        return array($version, $check_time);
      }
  
      public function generateToken()
          $feed = new FeedWriter(RSS2);
          $feed->setTitle('wallabag — ' . $type . ' feed');
          $feed->setLink(Tools::getPocheUrl());
 -        $feed->setChannelElement('updated', date(DATE_RSS , time()));
 -        $feed->setChannelElement('author', 'wallabag');
 +        $feed->setChannelElement('pubDate', date(DATE_RSS , time()));
 +        $feed->setChannelElement('generator', 'wallabag');
 +        $feed->setDescription('wallabag ' . $type . ' elements');
  
          if ($type == 'tag') {
              $entries = $this->store->retrieveEntriesByTag($tag_id, $user_id);
diff --combined index.php
index 06ab7d3c0b873c00133bfa644224359e9f431135,ecae911983ef77f92312a149037b0fae5e4f69fe..5ca8bef5b3de0af9c49a2737cd8859efd034c5c2
+++ b/index.php
@@@ -11,6 -11,7 +11,6 @@@
  define ('POCHE', '1.5.3');
  require 'check_setup.php';
  require_once 'inc/poche/global.inc.php';
 -session_start(); 
  
  # Start Poche
  $poche = new Poche();
@@@ -74,6 -75,8 +74,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();
diff --combined themes/baggy/config.twig
index d83b69abdb19eccb6977b02d1367463a2b1b32c3,8f35d797832d11c5d5cc6cebb7870e0164db662a..95db92fe6825b7afc90a99abb6213210ef1ad68d
@@@ -8,10 -8,9 +8,10 @@@
              <h2>{% trans "Saving articles" %}</h2>
              <p>{% trans "There are several ways to save an article:" %} (<a href="http://doc.wallabag.org/" title="{% trans "read the documentation" %}">?</a>)</p>
              <ul>
 -                <li>Firefox: <a href="https://addons.mozilla.org/firefox/addon/poche/" title="download the firefox extension">{% trans "download the extension" %}</a></li>
 +                <li>Firefox: <a href="https://addons.mozilla.org/firefox/addon/wallabag/" title="download the firefox extension">{% trans "download the extension" %}</a></li>
                  <li>Chrome: <a href="http://doc.wallabag.org/doku.php?id=users:chrome_extension" title="download the chrome extension">{% trans "download the extension" %}</a></li>
 -                <li>Android: <a href="https://f-droid.org/repository/browse/?fdid=fr.gaulupeau.apps.Poche" title="download the application">{% trans "via F-Droid" %}</a> {% trans " or " %} <a href="https://play.google.com/store/apps/details?id=fr.gaulupeau.apps.InThePoche" title="download the application">{% trans "via Google Play" %}</a></li>
 +                <li>Android: <a href="https://f-droid.org/app/fr.gaulupeau.apps.InThePoche" title="download the application">{% trans "via F-Droid" %}</a> {% trans " or " %} <a href="https://play.google.com/store/apps/details?id=fr.gaulupeau.apps.InThePoche" title="download the application">{% trans "via Google Play" %}</a></li>
 +                <li>iOS: <a href="https://itunes.apple.com/app/wallabag/id828331015?mt=8" title="download the iOS application">{% trans "download the application" %}</a></li>
                  <li>Windows Phone: <a href="https://www.windowsphone.com/en-us/store/app/poche/334de2f0-51b5-4826-8549-a3d805a37e83" title="download the window phone application">{% trans "download the application" %}</a></li>
                  <li>
                      <form method="get" action="index.php">
              <h2>{% trans "Upgrading wallabag" %}</h2>
              <ul>
                  <li>{% trans "Installed version" %} : <strong>{{ constant('POCHE') }}</strong></li>
 -                <li>{% trans "Latest stable version" %} : {{ prod }}. {% if compare_prod == -1 %}<strong><a href="http://wallabag.org/">{% trans "A more recent stable version is available." %}</a></strong>{% else %}{% trans "You are up to date." %}{% endif %}</li>
 -                {% if constant('DEBUG_POCHE') == 1 %}<li>{% trans "Latest dev version" %} : {{ dev }}. {% if compare_dev == -1 %}<strong><a href="http://wallabag.org/">{% trans "A more recent development version is available." %}</a></strong>{% else %}{% trans "You are up to date." %}{% endif %}</li>{% endif %}
 +                <li>{% trans "Latest stable version" %} : {{ prod }}. {% if compare_prod == -1 %}<strong><a href="http://wallabag.org/">{% trans "A more recent stable version is available." %}</a></strong>{% else %}{% trans "You are up to date." %}{% endif %} ({% trans "Last check:" %} {{ check_time_prod }})</li>
 +                {% if constant('DEBUG_POCHE') == 1 %}<li>{% trans "Latest dev version" %} : {{ dev }}. {% if compare_dev == -1 %}<strong><a href="http://wallabag.org/">{% trans "A more recent development version is available." %}</a></strong>{% else %}{% trans "You are up to date." %}{% endif %} ({% trans "Last check:" %} {{ check_time_dev }}){% endif %}</li>
              </ul>
 +            <p>{% trans "You can clear cache to check the latest release." %}</p>
  
              <h2>{% trans "Feeds" %}</h2>
              {% if token == '' %}
              {% 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>
  
+             {% if token == '' %}
+                 <p>{% trans "3. Your feed token is currently empty and must first be generated to fetch content. Click <a href='?feed&amp;action=generate'>here to generate it</a>." %}</p>
+             {% else %}
+             <p>3. {% trans "You can fetch content for imported items." %} <a href="cron.php?limit=10&amp;user-id={{ user_id }}&amp;token={{token}}" target="_blank">Click here</a> to fetch content for 10 articles.</p>
+             <p>{% trans "You can also create a cron task:" %}</p>
+             <pre><code>0 */4 * * *  cd /path/to/wallabag && php cron.php --limit=10 --user-id={{user_id}} --token={{token}} >/dev/null 2>&1</code></pre>
+             {% endif %}
              <h2>{% trans "Export your wallabag data" %}</h2>
              {% if constant('STORAGE') == 'sqlite' %}
              <p><a href="?download" target="_blank">{% trans "Click here" %}</a> {% trans "to download your database." %}</p>{% endif %}