123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342 |
- <?php
- if (!defined('STATUSNET')) {
-
-
- exit(1);
- }
- class ImportdeliciousAction extends Action
- {
- protected $success = false;
- private $inprogress = false;
-
- function title()
- {
-
- return _m("Import del.icio.us bookmarks");
- }
-
- function prepare(array $args = [])
- {
- parent::prepare($args);
- $cur = common_current_user();
- if (empty($cur)) {
-
- throw new ClientException(_m('Only logged-in users can ' .
- 'import del.icio.us backups.'),
- 403);
- }
- if (!$cur->hasRight(BookmarkPlugin::IMPORTDELICIOUS)) {
-
- throw new ClientException(_m('You may not restore your account.'), 403);
- }
- return true;
- }
-
- function handle()
- {
- parent::handle();
- if ($this->isPost()) {
- $this->importDelicious();
- } else {
- $this->showPage();
- }
- return;
- }
-
- function importDelicious()
- {
- $this->checkSessionToken();
- if (!isset($_FILES[ImportDeliciousForm::FILEINPUT]['error'])) {
-
- throw new ClientException(_m('No uploaded file.'));
- }
- switch ($_FILES[ImportDeliciousForm::FILEINPUT]['error']) {
- case UPLOAD_ERR_OK:
- break;
- case UPLOAD_ERR_INI_SIZE:
-
- throw new ClientException(_m('The uploaded file exceeds the ' .
- 'upload_max_filesize directive in php.ini.'));
- case UPLOAD_ERR_FORM_SIZE:
- throw new ClientException(
-
- _m('The uploaded file exceeds the MAX_FILE_SIZE directive' .
- ' that was specified in the HTML form.'));
- case UPLOAD_ERR_PARTIAL:
- @unlink($_FILES[ImportDeliciousForm::FILEINPUT]['tmp_name']);
-
- throw new ClientException(_m('The uploaded file was only' .
- ' partially uploaded.'));
- case UPLOAD_ERR_NO_FILE:
-
-
- throw new ClientException(_m('No uploaded file.'));
- case UPLOAD_ERR_NO_TMP_DIR:
-
- throw new ClientException(_m('Missing a temporary folder.'));
- case UPLOAD_ERR_CANT_WRITE:
-
- throw new ClientException(_m('Failed to write file to disk.'));
- case UPLOAD_ERR_EXTENSION:
-
- throw new ClientException(_m('File upload stopped by extension.'));
- default:
- common_log(LOG_ERR, __METHOD__ . ": Unknown upload error " .
- $_FILES[ImportDeliciousForm::FILEINPUT]['error']);
-
- throw new ClientException(_m('System error uploading file.'));
- }
- $filename = $_FILES[ImportDeliciousForm::FILEINPUT]['tmp_name'];
- try {
- if (!file_exists($filename)) {
-
-
- throw new ServerException(sprintf(_m('No such file "%s".'), $filename));
- }
- if (!is_file($filename)) {
-
-
- throw new ServerException(sprintf(_m('Not a regular file: "%s".'), $filename));
- }
- if (!is_readable($filename)) {
-
-
- throw new ServerException(sprintf(_m('File "%s" not readable.'), $filename));
- }
- common_debug(sprintf("Getting backup from file '%s'.", $filename));
- $html = file_get_contents($filename);
-
- $qm = QueueManager::get();
- $qm->enqueue([common_current_user(), $html], 'dlcsback');
- if ($qm instanceof UnQueueManager) {
-
- $this->success = true;
- } else {
-
- $this->inprogress = true;
- }
- $this->showPage();
- } catch (Exception $e) {
-
- @unlink($_FILES[ImportDeliciousForm::FILEINPUT]['tmp_name']);
- throw $e;
- }
- }
-
- function showContent()
- {
- if ($this->success) {
- $this->element('p', null,
-
- _m('Bookmarks have been imported. Your bookmarks should now appear in search and your profile page.'));
- } else if ($this->inprogress) {
- $this->element('p', null,
-
- _m('Bookmarks are being imported. Please wait a few minutes for results.'));
- } else {
- $form = new ImportDeliciousForm($this);
- $form->show();
- }
- }
-
- function isReadOnly($args)
- {
- return !$this->isPost();
- }
- }
- class ImportDeliciousForm extends Form
- {
- const FILEINPUT = 'deliciousbackupfile';
-
- function __construct($out = null)
- {
- parent::__construct($out);
- $this->enctype = 'multipart/form-data';
- }
-
- function formClass()
- {
- return 'form_import_delicious';
- }
-
- function action()
- {
- return common_local_url('importdelicious');
- }
-
- function formData()
- {
- $this->out->elementStart('p', 'instructions');
-
- $this->out->raw(_m('You can upload a backed-up ' .
- 'delicious.com bookmarks file.'));
- $this->out->elementEnd('p');
- $this->out->elementStart('ul', 'form_data');
- $this->out->elementStart('li', array('id' => 'settings_attach'));
- $this->out->element('input', array('name' => self::FILEINPUT,
- 'type' => 'file',
- 'id' => self::FILEINPUT));
- $this->out->elementEnd('li');
- $this->out->elementEnd('ul');
- }
-
- function formActions()
- {
- $this->out->submit('submit',
-
- _m('BUTTON', 'Upload'),
- 'submit',
- null,
-
- _m('Upload the file.'));
- }
- }
|