oldschoolsettings.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <?php
  2. /**
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2011, StatusNet, Inc.
  5. *
  6. * Settings panel for old-school UI
  7. *
  8. * PHP version 5
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. * @category Oldschool
  24. * @package StatusNet
  25. * @author Evan Prodromou <evan@status.net>
  26. * @copyright 2011 StatusNet, Inc.
  27. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  28. * @link http://status.net/
  29. */
  30. if (!defined('GNUSOCIAL')) { exit(1); }
  31. /**
  32. * Old-school settings
  33. *
  34. * @category Oldschool
  35. * @package StatusNet
  36. * @author Evan Prodromou <evan@status.net>
  37. * @copyright 2011 StatusNet, Inc.
  38. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  39. * @link http://status.net/
  40. */
  41. class OldschoolsettingsAction extends SettingsAction
  42. {
  43. /**
  44. * Title of the page
  45. *
  46. * @return string Title of the page
  47. */
  48. function title()
  49. {
  50. // TRANS: Page title for profile settings.
  51. return _('Old school UI settings');
  52. }
  53. /**
  54. * Instructions for use
  55. *
  56. * @return instructions for use
  57. */
  58. function getInstructions()
  59. {
  60. // TRANS: Usage instructions for profile settings.
  61. return _('If you like it "the old way", you can set that here.');
  62. }
  63. /**
  64. * For initializing members of the class.
  65. *
  66. * @param array $argarray misc. arguments
  67. *
  68. * @return boolean true
  69. */
  70. protected function doPreparation()
  71. {
  72. if (!common_config('oldschool', 'enabled')) {
  73. throw new ClientException("Old-school settings not enabled.");
  74. }
  75. }
  76. function doPost()
  77. {
  78. $osp = Old_school_prefs::getKV('user_id', $this->scoped->getID());
  79. $orig = null;
  80. if (!empty($osp)) {
  81. $orig = clone($osp);
  82. } else {
  83. $osp = new Old_school_prefs();
  84. $osp->user_id = $this->scoped->getID();
  85. $osp->created = common_sql_now();
  86. }
  87. $osp->stream_mode_only = $this->boolean('stream_mode_only');
  88. $osp->stream_nicknames = $this->boolean('stream_nicknames');
  89. $osp->modified = common_sql_now();
  90. if ($orig instanceof Old_school_prefs) {
  91. $osp->update($orig);
  92. } else {
  93. $osp->insert();
  94. }
  95. // TRANS: Confirmation shown when user profile settings are saved.
  96. return _('Settings saved.');
  97. }
  98. }
  99. class OldSchoolSettingsForm extends Form
  100. {
  101. var $user;
  102. function __construct(Action $out)
  103. {
  104. parent::__construct($out);
  105. $this->user = $out->getScoped()->getUser();
  106. }
  107. /**
  108. * Visible or invisible data elements
  109. *
  110. * Display the form fields that make up the data of the form.
  111. * Sub-classes should overload this to show their data.
  112. *
  113. * @return void
  114. */
  115. function formData()
  116. {
  117. $this->elementStart('fieldset');
  118. $this->elementStart('ul', 'form_data');
  119. $this->elementStart('li');
  120. $this->checkbox('stream_mode_only', _('Only stream mode (no conversations) in timelines'),
  121. $this->user->streamModeOnly());
  122. $this->elementEnd('li');
  123. $this->elementStart('li');
  124. $this->checkbox('stream_nicknames', _('Show nicknames (not full names) in timelines'),
  125. $this->user->streamNicknames());
  126. $this->elementEnd('li');
  127. $this->elementEnd('fieldset');
  128. $this->elementEnd('ul');
  129. }
  130. /**
  131. * Buttons for form actions
  132. *
  133. * Submit and cancel buttons (or whatever)
  134. * Sub-classes should overload this to show their own buttons.
  135. *
  136. * @return void
  137. */
  138. function formActions()
  139. {
  140. $this->submit('submit', _('Save'));
  141. }
  142. /**
  143. * ID of the form
  144. *
  145. * Should be unique on the page. Sub-classes should overload this
  146. * to show their own IDs.
  147. *
  148. * @return int ID of the form
  149. */
  150. function id()
  151. {
  152. return 'form_oldschool';
  153. }
  154. /**
  155. * Action of the form.
  156. *
  157. * URL to post to. Should be overloaded by subclasses to give
  158. * somewhere to post to.
  159. *
  160. * @return string URL to post to
  161. */
  162. function action()
  163. {
  164. return common_local_url('oldschoolsettings');
  165. }
  166. /**
  167. * Class of the form. May include space-separated list of multiple classes.
  168. *
  169. * @return string the form's class
  170. */
  171. function formClass()
  172. {
  173. return 'form_settings';
  174. }
  175. }