oldschoolsettings.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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('STATUSNET')) {
  31. // This check helps protect against security problems;
  32. // your code file can't be executed directly from the web.
  33. exit(1);
  34. }
  35. /**
  36. * Old-school settings
  37. *
  38. * @category Oldschool
  39. * @package StatusNet
  40. * @author Evan Prodromou <evan@status.net>
  41. * @copyright 2011 StatusNet, Inc.
  42. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  43. * @link http://status.net/
  44. */
  45. class OldschoolsettingsAction extends SettingsAction
  46. {
  47. /**
  48. * Title of the page
  49. *
  50. * @return string Title of the page
  51. */
  52. function title()
  53. {
  54. // TRANS: Page title for profile settings.
  55. return _('Old school UI settings');
  56. }
  57. /**
  58. * Instructions for use
  59. *
  60. * @return instructions for use
  61. */
  62. function getInstructions()
  63. {
  64. // TRANS: Usage instructions for profile settings.
  65. return _('If you like it "the old way", you can set that here.');
  66. }
  67. /**
  68. * For initializing members of the class.
  69. *
  70. * @param array $argarray misc. arguments
  71. *
  72. * @return boolean true
  73. */
  74. function prepare($argarray)
  75. {
  76. if (!common_config('oldschool', 'enabled')) {
  77. throw new ClientException("Old-school settings not enabled.");
  78. }
  79. parent::prepare($argarray);
  80. return true;
  81. }
  82. /**
  83. * Handler method
  84. *
  85. * @param array $argarray is ignored since it's now passed in in prepare()
  86. *
  87. * @return void
  88. */
  89. function handlePost()
  90. {
  91. $user = common_current_user();
  92. $osp = Old_school_prefs::getKV('user_id', $user->id);
  93. $orig = null;
  94. if (!empty($osp)) {
  95. $orig = clone($osp);
  96. } else {
  97. $osp = new Old_school_prefs();
  98. $osp->user_id = $user->id;
  99. $osp->created = common_sql_now();
  100. }
  101. $osp->stream_mode_only = $this->boolean('stream_mode_only');
  102. $osp->stream_nicknames = $this->boolean('stream_nicknames');
  103. $osp->modified = common_sql_now();
  104. if (!empty($orig)) {
  105. $osp->update($orig);
  106. } else {
  107. $osp->insert();
  108. }
  109. // TRANS: Confirmation shown when user profile settings are saved.
  110. $this->showForm(_('Settings saved.'), true);
  111. return;
  112. }
  113. function showContent()
  114. {
  115. $user = common_current_user();
  116. $form = new OldSchoolForm($this, $user);
  117. $form->show();
  118. }
  119. }
  120. class OldSchoolForm extends Form
  121. {
  122. var $user;
  123. function __construct($out, $user)
  124. {
  125. parent::__construct($out);
  126. $this->user = $user;
  127. }
  128. /**
  129. * Visible or invisible data elements
  130. *
  131. * Display the form fields that make up the data of the form.
  132. * Sub-classes should overload this to show their data.
  133. *
  134. * @return void
  135. */
  136. function formData()
  137. {
  138. $this->elementStart('fieldset');
  139. $this->elementStart('ul', 'form_data');
  140. $this->elementStart('li');
  141. $this->checkbox('stream_mode_only', _('Only stream mode (no conversations) in timelines'),
  142. $this->user->streamModeOnly());
  143. $this->elementEnd('li');
  144. $this->elementStart('li');
  145. $this->checkbox('stream_nicknames', _('Show nicknames (not full names) in timelines'),
  146. $this->user->streamNicknames());
  147. $this->elementEnd('li');
  148. $this->elementEnd('fieldset');
  149. $this->elementEnd('ul');
  150. }
  151. /**
  152. * Buttons for form actions
  153. *
  154. * Submit and cancel buttons (or whatever)
  155. * Sub-classes should overload this to show their own buttons.
  156. *
  157. * @return void
  158. */
  159. function formActions()
  160. {
  161. $this->submit('submit', _('Save'));
  162. }
  163. /**
  164. * ID of the form
  165. *
  166. * Should be unique on the page. Sub-classes should overload this
  167. * to show their own IDs.
  168. *
  169. * @return int ID of the form
  170. */
  171. function id()
  172. {
  173. return 'form_oldschool';
  174. }
  175. /**
  176. * Action of the form.
  177. *
  178. * URL to post to. Should be overloaded by subclasses to give
  179. * somewhere to post to.
  180. *
  181. * @return string URL to post to
  182. */
  183. function action()
  184. {
  185. return common_local_url('oldschoolsettings');
  186. }
  187. /**
  188. * Class of the form. May include space-separated list of multiple classes.
  189. *
  190. * @return string the form's class
  191. */
  192. function formClass()
  193. {
  194. return 'form_settings';
  195. }
  196. }