connectedappslist.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. /** Current connected application query */
  42. var $connection = null;
  43. /** Owner of this list */
  44. var $owner = null;
  45. function __construct($connection, Profile $owner, Action $out=null)
  46. {
  47. parent::__construct($out);
  48. common_debug("ConnectedAppsList constructor");
  49. $this->connection = $connection;
  50. $this->owner = $owner;
  51. }
  52. /* Override this in subclasses. */
  53. function showOwnerControls()
  54. {
  55. return;
  56. }
  57. function show()
  58. {
  59. $this->out->elementStart('ul', 'applications');
  60. $cnt = 0;
  61. while ($this->connection->fetch()) {
  62. $cnt++;
  63. if($cnt > APPS_PER_PAGE) {
  64. break;
  65. }
  66. $this->showConnection();
  67. }
  68. $this->out->elementEnd('ul');
  69. return $cnt;
  70. }
  71. function showConnection()
  72. {
  73. $app = Oauth_application::getKV('id', $this->connection->application_id);
  74. $this->out->elementStart('li', array('class' => 'application h-entry',
  75. 'id' => 'oauthclient-' . $app->id));
  76. $this->out->elementStart('a', array('href' => $app->source_url,
  77. 'class' => 'h-card p-name'));
  78. if (!empty($app->icon)) {
  79. $this->out->element('img', array('src' => $app->icon,
  80. 'class' => 'avatar u-photo'));
  81. }
  82. if ($app->name != 'anonymous') {
  83. $this->out->text($app->name);
  84. } else {
  85. // TRANS: Name for an anonymous application in application list.
  86. $this->out->element('span', 'p-name', _('Unknown application'));
  87. }
  88. $this->out->elementEnd('a');
  89. if ($app->name != 'anonymous') {
  90. // @todo FIXME: i18n trouble.
  91. // TRANS: Message has a leading space and a trailing space. Used in application list.
  92. // TRANS: Before this message the application name is put, behind it the organisation that manages it.
  93. $this->out->raw(_(' by '));
  94. $this->out->element('a', array('href' => $app->homepage,
  95. 'class' => 'h-card'),
  96. $app->organization);
  97. }
  98. // TRANS: Application access type
  99. $readWriteText = _('read-write');
  100. // TRANS: Application access type
  101. $readOnlyText = _('read-only');
  102. $access = ($this->connection->access_type & Oauth_application::$writeAccess)
  103. ? $readWriteText : $readOnlyText;
  104. $modifiedDate = common_date_string($this->connection->modified);
  105. // TRANS: Used in application list. %1$s is a modified date, %2$s is access type ("read-write" or "read-only")
  106. $txt = sprintf(_('Approved %1$s - "%2$s" access.'), $modifiedDate, $access);
  107. // @todo FIXME: i18n trouble.
  108. $this->out->raw(" - $txt");
  109. if (!empty($app->description)) {
  110. $this->out->element(
  111. 'p', array('class' => 'application_description'),
  112. $app->description
  113. );
  114. }
  115. $this->out->element(
  116. 'p', array(
  117. 'class' => 'access_token'),
  118. // TRANS: Access token in the application list.
  119. // TRANS: %s are the first 7 characters of the access token.
  120. sprintf(_('Access token starting with: %s'), substr($this->connection->token, 0, 7))
  121. );
  122. $this->out->elementStart(
  123. 'form',
  124. array(
  125. 'id' => 'form_revoke_app',
  126. 'class' => 'form_revoke_app',
  127. 'method' => 'POST',
  128. 'action' => common_local_url('oauthconnectionssettings')
  129. )
  130. );
  131. $this->out->elementStart('fieldset');
  132. $this->out->hidden('oauth_token', $this->connection->token);
  133. $this->out->hidden('token', common_session_token());
  134. // TRANS: Button label in application list to revoke access to user data.
  135. $this->out->submit('revoke', _m('BUTTON','Revoke'));
  136. $this->out->elementEnd('fieldset');
  137. $this->out->elementEnd('form');
  138. $this->out->elementEnd('li');
  139. }
  140. }