export-zip-for-user.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/env php
  2. <?php
  3. require(__DIR__ . '/_cli.php');
  4. performRequirementCheck(FreshRSS_Context::$system_conf->db['type']);
  5. $params = array(
  6. 'user:',
  7. 'max-feed-entries:',
  8. );
  9. $options = getopt('', $params);
  10. if (!validateOptions($argv, $params) || empty($options['user'])) {
  11. fail('Usage: ' . basename(__FILE__) . " --user username ( --max-feed-entries 100 ) > /path/to/file.zip");
  12. }
  13. if (!extension_loaded('zip')) {
  14. fail('FreshRSS error: Lacking php-zip extension!');
  15. }
  16. $username = cliInitUser($options['user']);
  17. fwrite(STDERR, 'FreshRSS exporting ZIP for user “' . $username . "”…\n");
  18. $export_service = new FreshRSS_Export_Service($username);
  19. $number_entries = empty($options['max-feed-entries']) ? 100 : intval($options['max-feed-entries']);
  20. $exported_files = [];
  21. // First, we generate the OPML file
  22. list($filename, $content) = $export_service->generateOpml();
  23. $exported_files[$filename] = $content;
  24. // Then, labelled and starred entries
  25. list($filename, $content) = $export_service->generateStarredEntries('ST');
  26. $exported_files[$filename] = $content;
  27. // And a list of entries based on the complete list of feeds
  28. $feeds_exported_files = $export_service->generateAllFeedEntries($number_entries);
  29. $exported_files = array_merge($exported_files, $feeds_exported_files);
  30. // Finally, we compress all these files into a single Zip archive and we output
  31. // the content
  32. list($filename, $content) = $export_service->zip($exported_files);
  33. echo $content;
  34. invalidateHttpCache($username);
  35. done();