oauthappssettings.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. // This file is part of GNU social - https://www.gnu.org/software/social
  3. //
  4. // GNU social is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Affero General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // GNU social is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Affero General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Affero General Public License
  15. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * List the OAuth applications that a user has registered with this instance
  18. *
  19. * @category Settings
  20. * @package GNUsocial
  21. * @author Zach Copley <zach@status.net>
  22. * @copyright 2008-2009 StatusNet, Inc.
  23. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  24. */
  25. defined('GNUSOCIAL') || die();
  26. /**
  27. * Show a user's registered OAuth applications
  28. *
  29. * @category Settings
  30. * @package GNUsocial
  31. * @author Zach Copley <zach@status.net>
  32. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  33. *
  34. * @see SettingsAction
  35. */
  36. class OauthappssettingsAction extends SettingsAction
  37. {
  38. protected $page = null;
  39. protected function doPreparation()
  40. {
  41. $this->page = $this->int('page') ?: 1;
  42. }
  43. /**
  44. * Title of the page
  45. *
  46. * @return string Title of the page
  47. */
  48. public function title()
  49. {
  50. // TRANS: Page title for OAuth applications
  51. return _('OAuth applications');
  52. }
  53. /**
  54. * Instructions for use
  55. *
  56. * @return instructions for use
  57. */
  58. public function getInstructions()
  59. {
  60. // TRANS: Page instructions for OAuth applications
  61. return _('Applications you have registered');
  62. }
  63. public function showContent()
  64. {
  65. $offset = ($this->page - 1) * APPS_PER_PAGE;
  66. $limit = APPS_PER_PAGE + 1;
  67. $application = new Oauth_application();
  68. $application->owner = $this->scoped->getID();
  69. $application->whereAdd("name <> 'anonymous'");
  70. $application->limit($offset, $limit);
  71. $application->orderBy('created DESC');
  72. $application->find();
  73. $cnt = 0;
  74. if ($application) {
  75. $al = new ApplicationList($application, $this->scoped, $this);
  76. $cnt = $al->show();
  77. if (0 == $cnt) {
  78. $this->showEmptyListMessage();
  79. }
  80. }
  81. $this->elementStart('p', ['id' => 'application_register']);
  82. $this->element(
  83. 'a',
  84. [
  85. 'href' => common_local_url('newapplication'),
  86. 'class' => 'more',
  87. ],
  88. // TRANS: Link description to add a new OAuth application.
  89. 'Register a new application'
  90. );
  91. $this->elementEnd('p');
  92. $this->pagination(
  93. $this->page > 1,
  94. $cnt > APPS_PER_PAGE,
  95. $this->page,
  96. 'oauthappssettings'
  97. );
  98. }
  99. public function showEmptyListMessage()
  100. {
  101. // TRANS: Empty list message on page with OAuth applications. Markup allowed
  102. $message = sprintf(_('You have not registered any applications yet.'));
  103. $this->elementStart('div', 'guide');
  104. $this->raw(common_markup_to_html($message));
  105. $this->elementEnd('div');
  106. }
  107. }