applicationlist.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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('STATUSNET') && !defined('LACONICA')) {
  30. exit(1);
  31. }
  32. require_once INSTALLDIR . '/lib/widget.php';
  33. define('APPS_PER_PAGE', 20);
  34. /**
  35. * Widget to show a list of OAuth applications
  36. *
  37. * @category Application
  38. * @package StatusNet
  39. * @author Zach Copley <zach@status.net>
  40. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  41. * @link http://status.net/
  42. */
  43. class ApplicationList extends Widget
  44. {
  45. /** Current application, application query */
  46. var $application = null;
  47. /** Owner of this list */
  48. var $owner = null;
  49. /** Action object using us. */
  50. var $action = null;
  51. function __construct($application, $owner=null, $action=null)
  52. {
  53. parent::__construct($action);
  54. $this->application = $application;
  55. $this->owner = $owner;
  56. $this->action = $action;
  57. }
  58. function show()
  59. {
  60. $this->out->elementStart('ul', 'applications');
  61. $cnt = 0;
  62. while ($this->application->fetch()) {
  63. $cnt++;
  64. if($cnt > APPS_PER_PAGE) {
  65. break;
  66. }
  67. $this->showapplication();
  68. }
  69. $this->out->elementEnd('ul');
  70. return $cnt;
  71. }
  72. function showApplication()
  73. {
  74. $user = common_current_user();
  75. $this->out->elementStart('li', array('class' => 'application h-entry',
  76. 'id' => 'oauthclient-' . $this->application->id));
  77. $this->out->elementStart('a', array('href' => common_local_url('showapplication',
  78. array('id' => $this->application->id)),
  79. 'class' => 'h-card'));
  80. if (!empty($this->application->icon)) {
  81. $this->out->element('img', array('src' => $this->application->icon,
  82. 'class' => 'avatar u-photo'));
  83. }
  84. $this->out->text($this->application->name);
  85. $this->out->elementEnd('a');
  86. $this->out->raw(' by ');
  87. $this->out->element('a', array('href' => $this->application->homepage,
  88. 'class' => 'u-url'),
  89. $this->application->organization);
  90. $this->out->element('p', 'note', $this->application->description);
  91. $this->out->elementEnd('li');
  92. }
  93. /* Override this in subclasses. */
  94. function showOwnerControls()
  95. {
  96. return;
  97. }
  98. }
  99. /**
  100. * Widget to show a list of connected OAuth clients
  101. *
  102. * @category Application
  103. * @package StatusNet
  104. * @author Zach Copley <zach@status.net>
  105. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  106. * @link http://status.net/
  107. */
  108. class ConnectedAppsList extends Widget
  109. {
  110. /** Current connected application query */
  111. var $connection = null;
  112. /** Owner of this list */
  113. var $owner = null;
  114. /** Action object using us. */
  115. var $action = null;
  116. function __construct($connection, $owner=null, $action=null)
  117. {
  118. parent::__construct($action);
  119. common_debug("ConnectedAppsList constructor");
  120. $this->connection = $connection;
  121. $this->owner = $owner;
  122. $this->action = $action;
  123. }
  124. /* Override this in subclasses. */
  125. function showOwnerControls()
  126. {
  127. return;
  128. }
  129. function show()
  130. {
  131. $this->out->elementStart('ul', 'applications');
  132. $cnt = 0;
  133. while ($this->connection->fetch()) {
  134. $cnt++;
  135. if($cnt > APPS_PER_PAGE) {
  136. break;
  137. }
  138. $this->showConnection();
  139. }
  140. $this->out->elementEnd('ul');
  141. return $cnt;
  142. }
  143. function showConnection()
  144. {
  145. $app = Oauth_application::getKV('id', $this->connection->application_id);
  146. $this->out->elementStart('li', array('class' => 'application h-entry',
  147. 'id' => 'oauthclient-' . $app->id));
  148. $this->out->elementStart('a', array('href' => $app->source_url,
  149. 'class' => 'h-card p-name'));
  150. if (!empty($app->icon)) {
  151. $this->out->element('img', array('src' => $app->icon,
  152. 'class' => 'avatar u-photo'));
  153. }
  154. if ($app->name != 'anonymous') {
  155. $this->out->text($app->name);
  156. } else {
  157. // TRANS: Name for an anonymous application in application list.
  158. $this->out->element('span', 'p-name', _('Unknown application'));
  159. }
  160. $this->out->elementEnd('a');
  161. if ($app->name != 'anonymous') {
  162. // @todo FIXME: i18n trouble.
  163. // TRANS: Message has a leading space and a trailing space. Used in application list.
  164. // TRANS: Before this message the application name is put, behind it the organisation that manages it.
  165. $this->out->raw(_(' by '));
  166. $this->out->element('a', array('href' => $app->homepage,
  167. 'class' => 'h-card'),
  168. $app->organization);
  169. }
  170. // TRANS: Application access type
  171. $readWriteText = _('read-write');
  172. // TRANS: Application access type
  173. $readOnlyText = _('read-only');
  174. $access = ($this->connection->access_type & Oauth_application::$writeAccess)
  175. ? $readWriteText : $readOnlyText;
  176. $modifiedDate = common_date_string($this->connection->modified);
  177. // TRANS: Used in application list. %1$s is a modified date, %2$s is access type ("read-write" or "read-only")
  178. $txt = sprintf(_('Approved %1$s - "%2$s" access.'), $modifiedDate, $access);
  179. // @todo FIXME: i18n trouble.
  180. $this->out->raw(" - $txt");
  181. if (!empty($app->description)) {
  182. $this->out->element(
  183. 'p', array('class' => 'application_description'),
  184. $app->description
  185. );
  186. }
  187. $this->out->element(
  188. 'p', array(
  189. 'class' => 'access_token'),
  190. // TRANS: Access token in the application list.
  191. // TRANS: %s are the first 7 characters of the access token.
  192. sprintf(_('Access token starting with: %s'), substr($this->connection->token, 0, 7))
  193. );
  194. $this->out->elementStart(
  195. 'form',
  196. array(
  197. 'id' => 'form_revoke_app',
  198. 'class' => 'form_revoke_app',
  199. 'method' => 'POST',
  200. 'action' => common_local_url('oauthconnectionssettings')
  201. )
  202. );
  203. $this->out->elementStart('fieldset');
  204. $this->out->hidden('oauth_token', $this->connection->token);
  205. $this->out->hidden('token', common_session_token());
  206. // TRANS: Button label in application list to revoke access to user data.
  207. $this->out->submit('revoke', _m('BUTTON','Revoke'));
  208. $this->out->elementEnd('fieldset');
  209. $this->out->elementEnd('form');
  210. $this->out->elementEnd('li');
  211. }
  212. }