You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
3.5 KiB

  1. <?php
  2. /**
  3. * @package Widgets
  4. *
  5. * @file Subscribe.php
  6. * This file is part of MOVIM.
  7. *
  8. * @brief The account creation widget.
  9. *
  10. * @author Timothée Jaussoin <edhelas@gmail.com>
  11. *
  12. * @version 1.0
  13. * @date 25 November 2011
  14. *
  15. * Copyright (C)2010 MOVIM project
  16. *
  17. * See COPYING for licensing information.
  18. */
  19. use Moxl\Xec\Action\Disco\Request;
  20. use Moxl\Xec\Action\Register\Get;
  21. use Moxl\Xec\Action\Register\Set;
  22. class AccountNext extends WidgetBase {
  23. function load()
  24. {
  25. $this->addjs('accountnext.js');
  26. $this->registerEvent('register_get_handle', 'onForm');
  27. $this->registerEvent('register_set_handle', 'onRegistered');
  28. $this->registerEvent('register_set_errorconflict', 'onRegisterError');
  29. $this->registerEvent('register_set_errornotacceptable', 'onRegisterNotAcceptable');
  30. $this->registerEvent('register_get_errorserviceunavailable', 'onServiceUnavailable');
  31. }
  32. function display()
  33. {
  34. $host = $_GET['s'];
  35. $this->view->assign('getsubscriptionform', $this->call('ajaxGetForm', "'".$host."'"));
  36. $this->view->assign('host', $host);
  37. }
  38. function onForm($package)
  39. {
  40. $form = $package->content;
  41. $xtf = new \XMPPtoForm();
  42. if(!empty($form->x)){
  43. $ns = $form->x->getNamespaces();
  44. switch($ns['']) {
  45. case 'jabber:x:data' :
  46. $formview = $this->tpl();
  47. $formh = $xtf->getHTML($form->x->asXML());
  48. $formview->assign('submitdata', $this->call('ajaxRegister', "movim_form_to_json('data')"));
  49. $formview->assign('formh', $formh);
  50. $html = $formview->draw('_accountnext_form', true);
  51. RPC::call('movim_fill', 'subscription_form', $html);
  52. break;
  53. case 'jabber:x:oob' :
  54. $oobview = $this->tpl();
  55. $oobview->assign('url', (string)$form->x->url);
  56. $html = $oobview->draw('_accountnext_oob', true);
  57. RPC::call('movim_fill', 'subscription_form', $html);
  58. RPC::call('remoteUnregister');
  59. break;
  60. }
  61. } else{
  62. $formh = $xtf->getHTML($form->asXML());
  63. }
  64. }
  65. function onRegistered($packet)
  66. {
  67. $data = $packet->content;
  68. $view = $this->tpl();
  69. $view->assign('url', (string)$form->x->url);
  70. $html = $view->draw('_accountnext_registered', true);
  71. RPC::call('movim_fill', 'subscription_form', $html);
  72. RPC::call('setUsername', $data->username->value);
  73. RPC::call('remoteUnregister');
  74. }
  75. function onRegisterError($package)
  76. {
  77. $error = $package->content;
  78. RPC::call('movim_fill', 'subscription_error', '<div class="message error">'.$error.'</div>');
  79. }
  80. function onRegisterNotAcceptable()
  81. {
  82. RPC::call('movim_fill', 'subscription_error', '<div class="message error">'.$this->__('error.not_acceptable').'</div>');
  83. }
  84. function onServiceUnavailable()
  85. {
  86. RPC::call('movim_fill', 'subscription_form', '<div class="message error">'.$this->__('error.service_unavailable').'</div>');
  87. RPC::call('remoteUnregister');
  88. }
  89. function ajaxGetForm($host)
  90. {
  91. \Moxl\Stanza\Stream::init($host);
  92. }
  93. function ajaxRegister($form)
  94. {
  95. $s = new Set;
  96. $s->setData($form)->request();
  97. }
  98. }