qvittersettings.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <?php
  2. /* · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·
  3. · ·
  4. · ·
  5. · Q V I T T E R ·
  6. · ·
  7. · https://git.gnu.io/h2p/Qvitter ·
  8. · ·
  9. · ·
  10. · <o) ·
  11. · /_//// ·
  12. · (____/ ·
  13. · (o< ·
  14. · o> \\\\_\ ·
  15. · \\) \____) ·
  16. · ·
  17. · ·
  18. · ·
  19. · Qvitter is free software: you can redistribute it and / or modify it ·
  20. · under the terms of the GNU Affero General Public License as published by ·
  21. · the Free Software Foundation, either version three of the License or (at ·
  22. · your option) any later version. ·
  23. · ·
  24. · Qvitter is distributed in hope that it will be useful but WITHOUT ANY ·
  25. · WARRANTY; without even the implied warranty of MERCHANTABILTY or FITNESS ·
  26. · FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for ·
  27. · more details. ·
  28. · ·
  29. · You should have received a copy of the GNU Affero General Public License ·
  30. · along with Qvitter. If not, see <http://www.gnu.org/licenses/>. ·
  31. · ·
  32. · Contact h@nnesmannerhe.im if you have any questions. ·
  33. · ·
  34. · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · */
  35. if (!defined('STATUSNET') && !defined('LACONICA')) {
  36. exit(1);
  37. }
  38. class QvitterSettingsAction extends SettingsAction
  39. {
  40. /**
  41. * Title of the page
  42. *
  43. * @return string Page title
  44. */
  45. function title()
  46. {
  47. // TRANS: Page title.
  48. return _m('Qvitter settings');
  49. }
  50. /**
  51. * Instructions for use
  52. *
  53. * @return string Instructions for use
  54. */
  55. function getInstructions()
  56. {
  57. // TRANS: Page instructions.
  58. return _m('Qvitter Settings');
  59. }
  60. /**
  61. * Show the form for Qvitter
  62. *
  63. * @return void
  64. */
  65. function showContent()
  66. {
  67. $user = common_current_user();
  68. if(QvitterPlugin::settings('enabledbydefault')) {
  69. try {
  70. $disable_enable_prefs = Profile_prefs::getData($user->getProfile(), 'qvitter', 'disable_qvitter');
  71. } catch (NoResultException $e) {
  72. $disable_enable_prefs = false;
  73. }
  74. } else {
  75. try {
  76. $disable_enable_prefs = Profile_prefs::getData($user->getProfile(), 'qvitter', 'enable_qvitter');
  77. } catch (NoResultException $e) {
  78. $disable_enable_prefs = false;
  79. }
  80. }
  81. try {
  82. $hide_replies_prefs = Profile_prefs::getData($user->getProfile(), 'qvitter', 'hide_replies');
  83. } catch (NoResultException $e) {
  84. $hide_replies_prefs = false;
  85. }
  86. try {
  87. $disable_keyboard_shortcuts = Profile_prefs::getData($user->getProfile(), 'qvitter', 'disable_keyboard_shortcuts');
  88. } catch (NoResultException $e) {
  89. $disable_keyboard_shortcuts = false;
  90. }
  91. $form = new QvitterPrefsForm($this, $disable_enable_prefs, $hide_replies_prefs, $disable_keyboard_shortcuts);
  92. $form->show();
  93. }
  94. /**
  95. * Handler method
  96. *
  97. * @param array $argarray is ignored since it's now passed in in prepare()
  98. *
  99. * @return void
  100. */
  101. function handlePost()
  102. {
  103. $user = common_current_user();
  104. if(QvitterPlugin::settings('enabledbydefault')) {
  105. Profile_prefs::setData($user->getProfile(), 'qvitter', 'disable_qvitter', $this->boolean('disable_qvitter'));
  106. }
  107. else {
  108. Profile_prefs::setData($user->getProfile(), 'qvitter', 'enable_qvitter', $this->boolean('enable_qvitter'));
  109. }
  110. Profile_prefs::setData($user->getProfile(), 'qvitter', 'hide_replies', $this->boolean('hide_replies'));
  111. Profile_prefs::setData($user->getProfile(), 'qvitter', 'disable_keyboard_shortcuts', $this->boolean('disable_keyboard_shortcuts'));
  112. // TRANS: Confirmation shown when user profile settings are saved.
  113. $this->showForm(_('Settings saved.'), true);
  114. return;
  115. }
  116. }
  117. class QvitterPrefsForm extends Form
  118. {
  119. var $disable_enable_prefs;
  120. var $hide_replies_prefs;
  121. var $disable_keyboard_shortcuts;
  122. function __construct($out, $disable_enable_prefs, $hide_replies_prefs, $disable_keyboard_shortcuts)
  123. {
  124. parent::__construct($out);
  125. $this->disable_enable_prefs = $disable_enable_prefs;
  126. $this->hide_replies_prefs = $hide_replies_prefs;
  127. $this->disable_keyboard_shortcuts = $disable_keyboard_shortcuts;
  128. }
  129. /**
  130. * Visible or invisible data elements
  131. *
  132. * Display the form fields that make up the data of the form.
  133. * Sub-classes should overload this to show their data.
  134. *
  135. * @return void
  136. */
  137. function formData()
  138. {
  139. if(QvitterPlugin::settings('enabledbydefault')) {
  140. $enabledisable = 'disable_qvitter';
  141. $enabledisablelabel = _('Disable Qvitter');
  142. } else {
  143. $enabledisable = 'enable_qvitter';
  144. $enabledisablelabel = _('Enable Qvitter');
  145. }
  146. $this->elementStart('fieldset');
  147. $this->elementStart('ul', 'form_data');
  148. $this->elementStart('li');
  149. $this->checkbox($enabledisable,
  150. $enabledisablelabel,
  151. (!empty($this->disable_enable_prefs)));
  152. $this->elementEnd('li');
  153. $this->elementEnd('ul');
  154. $this->elementEnd('fieldset');
  155. $this->elementStart('fieldset');
  156. $this->elementStart('ul', 'form_data');
  157. $this->elementStart('li');
  158. $this->checkbox('hide_replies',
  159. _('Hide replies to people I\'m not following'),
  160. (!empty($this->hide_replies_prefs)));
  161. $this->elementEnd('li');
  162. $this->elementEnd('ul');
  163. $this->elementEnd('fieldset');
  164. $this->elementStart('fieldset');
  165. $this->elementStart('ul', 'form_data');
  166. $this->elementStart('li');
  167. $this->checkbox('disable_keyboard_shortcuts',
  168. _('Disable keyboard shortcuts'),
  169. (!empty($this->disable_keyboard_shortcuts)));
  170. $this->elementEnd('li');
  171. $this->elementEnd('ul');
  172. $this->elementEnd('fieldset');
  173. }
  174. /**
  175. * Buttons for form actions
  176. *
  177. * Submit and cancel buttons (or whatever)
  178. * Sub-classes should overload this to show their own buttons.
  179. *
  180. * @return void
  181. */
  182. function formActions()
  183. {
  184. $this->submit('submit', _('Save'));
  185. }
  186. /**
  187. * ID of the form
  188. *
  189. * Should be unique on the page. Sub-classes should overload this
  190. * to show their own IDs.
  191. *
  192. * @return int ID of the form
  193. */
  194. function id()
  195. {
  196. return 'form_qvitter_prefs';
  197. }
  198. /**
  199. * Action of the form.
  200. *
  201. * URL to post to. Should be overloaded by subclasses to give
  202. * somewhere to post to.
  203. *
  204. * @return string URL to post to
  205. */
  206. function action()
  207. {
  208. return common_local_url('qvittersettings');
  209. }
  210. /**
  211. * Class of the form. May include space-separated list of multiple classes.
  212. *
  213. * @return string the form's class
  214. */
  215. function formClass()
  216. {
  217. return 'form_settings';
  218. }
  219. }