export-zip-for-user.php 1.4 KB

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