connectedappslist.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Widget to show a list of OAuth applications
  6. *
  7. * PHP version 5
  8. *
  9. * LICENCE: This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. * @category Application
  23. * @package StatusNet
  24. * @author Zach Copley <zach@status.net>
  25. * @copyright 2008-2010 StatusNet, Inc.
  26. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  27. * @link http://status.net/
  28. */
  29. if (!defined('GNUSOCIAL')) { exit(1); }
  30. /**
  31. * Widget to show a list of connected OAuth clients
  32. *
  33. * @category Application
  34. * @package StatusNet
  35. * @author Zach Copley <zach@status.net>
  36. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  37. * @link http://status.net/
  38. */
  39. class ConnectedAppsList extends Widget
  40. {
  41. public $widgetOpts;
  42. public $scoped;
  43. /** Current connected application query */
  44. var $connection = null;
  45. /** Owner of this list */
  46. var $owner = null;
  47. function __construct($connection, Profile $owner, Action $out=null)
  48. {
  49. parent::__construct($out);
  50. common_debug("ConnectedAppsList constructor");
  51. $this->connection = $connection;
  52. $this->owner = $owner;
  53. }
  54. /* Override this in subclasses. */
  55. function showOwnerControls()
  56. {
  57. return;
  58. }
  59. function show()
  60. {
  61. $this->out->elementStart('ul', 'applications');
  62. $cnt = 0;
  63. while ($this->connection->fetch()) {
  64. $cnt++;
  65. if($cnt > APPS_PER_PAGE) {
  66. break;
  67. }
  68. $this->showConnection();
  69. }
  70. $this->out->elementEnd('ul');
  71. return $cnt;
  72. }
  73. function showConnection()
  74. {
  75. $app = Oauth_application::getKV('id', $this->connection->application_id);
  76. $this->out->elementStart('li', array('class' => 'application h-entry',
  77. 'id' => 'oauthclient-' . $app->id));
  78. $this->out->elementStart('a', array('href' => $app->source_url,
  79. 'class' => 'h-card p-name'));
  80. if (!empty($app->icon)) {
  81. $this->out->element('img', array('src' => $app->icon,
  82. 'class' => 'avatar u-photo'));
  83. }
  84. if ($app->name != 'anonymous') {
  85. $this->out->text($app->name);
  86. } else {
  87. // TRANS: Name for an anonymous application in application list.
  88. $this->out->element('span', 'p-name', _('Unknown application'));
  89. }
  90. $this->out->elementEnd('a');
  91. if ($app->name != 'anonymous') {
  92. // @todo FIXME: i18n trouble.
  93. // TRANS: Message has a leading space and a trailing space. Used in application list.
  94. // TRANS: Before this message the application name is put, behind it the organisation that manages it.
  95. $this->out->raw(_(' by '));
  96. $this->out->element('a', array('href' => $app->homepage,
  97. 'class' => 'h-card'),
  98. $app->organization);
  99. }
  100. // TRANS: Application access type
  101. $readWriteText = _('read-write');
  102. // TRANS: Application access type
  103. $readOnlyText = _('read-only');
  104. $access = ($this->connection->access_type & Oauth_application::$writeAccess)
  105. ? $readWriteText : $readOnlyText;
  106. $modifiedDate = common_date_string($this->connection->modified);
  107. // TRANS: Used in application list. %1$s is a modified date, %2$s is access type ("read-write" or "read-only")
  108. $txt = sprintf(_('Approved %1$s - "%2$s" access.'), $modifiedDate, $access);
  109. // @todo FIXME: i18n trouble.
  110. $this->out->raw(" - $txt");
  111. if (!empty($app->description)) {
  112. $this->out->element(
  113. 'p', array('class' => 'application_description'),
  114. $app->description
  115. );
  116. }
  117. $this->out->element(
  118. 'p', array(
  119. 'class' => 'access_token'),
  120. // TRANS: Access token in the application list.
  121. // TRANS: %s are the first 7 characters of the access token.
  122. sprintf(_('Access token starting with: %s'), substr($this->connection->token, 0, 7))
  123. );
  124. $this->out->elementStart(
  125. 'form',
  126. array(
  127. 'id' => 'form_revoke_app',
  128. 'class' => 'form_revoke_app',
  129. 'method' => 'POST',
  130. 'action' => common_local_url('oauthconnectionssettings')
  131. )
  132. );
  133. $this->out->elementStart('fieldset');
  134. $this->out->hidden('oauth_token', $this->connection->token);
  135. $this->out->hidden('token', common_session_token());
  136. // TRANS: Button label in application list to revoke access to user data.
  137. $this->out->submit('revoke', _m('BUTTON','Revoke'));
  138. $this->out->elementEnd('fieldset');
  139. $this->out->elementEnd('form');
  140. $this->out->elementEnd('li');
  141. }
  142. }