importbookmarks.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!/usr/bin/env php
  2. <?php
  3. // This file is part of GNU social - https://www.gnu.org/software/social
  4. //
  5. // GNU social is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU Affero General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // GNU social is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU Affero General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Affero General Public License
  16. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  17. /**
  18. * @category Bookmark
  19. * @package GNUsocial
  20. * @author Evan Prodromou <evan@status.net>
  21. * @copyright 2010 StatusNet, Inc.
  22. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  23. */
  24. define('INSTALLDIR', dirname(__DIR__, 3));
  25. define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
  26. $shortoptions = 'i:n:f:';
  27. $longoptions = array('id=', 'nickname=', 'file=');
  28. $helptext = <<<END_OF_IMPORTBOOKMARKS_HELP
  29. importbookmarks.php [options]
  30. Restore a backed-up Delicious.com bookmark file
  31. -i --id ID of user to import bookmarks for
  32. -n --nickname nickname of the user to import for
  33. -f --file file to read from (STDIN by default)
  34. END_OF_IMPORTBOOKMARKS_HELP;
  35. require_once INSTALLDIR.'/scripts/commandline.inc';
  36. /**
  37. * Get the bookmarks file as a string
  38. *
  39. * Uses the -f or --file parameter to open and read a
  40. * a bookmarks file
  41. *
  42. * @return string Contents of the file
  43. */
  44. function getBookmarksFile()
  45. {
  46. $filename = get_option_value('f', 'file');
  47. if (empty($filename)) {
  48. show_help();
  49. exit(1);
  50. }
  51. if (!file_exists($filename)) {
  52. // TRANS: Exception thrown when a file upload cannot be found.
  53. // TRANS: %s is the file that could not be found.
  54. throw new Exception(sprintf(_m('No such file "%s".'), $filename));
  55. }
  56. if (!is_file($filename)) {
  57. // TRANS: Exception thrown when a file upload is incorrect.
  58. // TRANS: %s is the irregular file.
  59. throw new Exception(sprintf(_m('Not a regular file: "%s".'), $filename));
  60. }
  61. if (!is_readable($filename)) {
  62. // TRANS: Exception thrown when a file upload is not readable.
  63. // TRANS: %s is the file that could not be read.
  64. throw new Exception(sprintf(_m('File "%s" not readable.'), $filename));
  65. }
  66. // TRANS: %s is the filename that contains a backup for a user.
  67. printfv(_m('Getting backup from file "%s".')."\n", $filename);
  68. $html = file_get_contents($filename);
  69. return $html;
  70. }
  71. try {
  72. $user = getUser();
  73. $html = getBookmarksFile();
  74. $qm = QueueManager::get();
  75. $qm->enqueue(array($user, $html), 'dlcsback');
  76. } catch (Exception $e) {
  77. print $e->getMessage()."\n";
  78. exit(1);
  79. }