choosethemesettings.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <?php
  2. /**
  3. * ChooseTheme - GNU social plugin enabling user to select preferred theme
  4. * Copyright (C) 2015, kollektivet0x242.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. * @author Knut Erik Hollund <knut.erik@unlike.no>
  20. * @copyright 2015 kollektivet0x242. http://www.kollektivet0x242.no
  21. *
  22. * @license GNU Affero General Public License http://www.gnu.org/licenses/
  23. */
  24. if (!defined('STATUSNET') && !defined('GNUSOCIAL')) {
  25. exit(1);
  26. }
  27. class ChooseThemeSettingsAction extends SettingsAction {
  28. /**
  29. * Title of the page
  30. * @return string Page title
  31. */
  32. function title() {
  33. // TRANS: Page title.
  34. return _m('Choose theme settings');
  35. }
  36. /**
  37. * Instructions for use
  38. * @return string Instructions for use
  39. */
  40. function getInstructions() {
  41. // TRANS: Page instructions.
  42. return _m('Choose theme');
  43. }
  44. /**
  45. * Show the form for ChooseTheme
  46. * @return void
  47. */
  48. function showContent() {
  49. $site_theme = common_config('site','theme');
  50. $prefs = $this->scoped->getPref('chosen_theme', 'theme',$site_theme);
  51. if ($prefs === null) {
  52. common_debug('No chosen theme found in database for user.');
  53. }
  54. //Get a list of available themes on instance
  55. $available_themes = Theme::listAvailable();
  56. $chosenone = array_search($prefs,$available_themes,true);
  57. $form = new ChooseThemeForm($this, $chosenone);
  58. $form->show();
  59. }
  60. /**
  61. * Handler method
  62. *
  63. * @param array $argarray is ignored since it's now passed in in prepare()
  64. * @return void
  65. */
  66. function handlePost() {
  67. //Get a list of available themes on instance
  68. $available_themes = Theme::listAvailable();
  69. $chosen_theme = $available_themes[(int)$this->arg('dwct','0')];
  70. $this->success = true;
  71. $this->msg = _m('Settings saved.');
  72. $this->success = $this->scoped->setPref('chosen_theme', 'theme', $chosen_theme);
  73. // TRANS: Confirmation shown when user profile settings are saved.
  74. if(!$this->success) $this->msg = _('No valid theme chosen.');
  75. $this->showForm(_($this->msg), $this->success);
  76. }
  77. }
  78. class ChooseThemeForm extends Form {
  79. protected $prefs = null;
  80. function __construct($out, $prefs) {
  81. parent::__construct($out);
  82. if ($prefs!=null) {
  83. $this->prefs = $prefs;
  84. } else {
  85. $prefs = common_config('site','theme');
  86. }
  87. }
  88. /**
  89. * Visible or invisible data elements
  90. *
  91. * Display the form fields that make up the data of the form.
  92. * Sub-classes should overload this to show their data.
  93. * @return void
  94. */
  95. function formData() {
  96. //Get a list of available themes on instance
  97. $available_themes = Theme::listAvailable();
  98. //Remove theme 'licenses' from selectable themes.
  99. //The 'licenses' theme is not an actual theme and
  100. //will just mess-up the gui.
  101. $key = array_search('licenses',$available_themes);
  102. if($key!=false){
  103. unset($available_themes[$key]);
  104. }
  105. $this->elementStart('fieldset');
  106. $this->elementStart('ul', 'form_data');
  107. $this->elementStart('li');
  108. $this->dropdown('dwct',_m('Themes'),$available_themes,_m('Select a theme'),false, $this->prefs);
  109. $this->elementEnd('li');
  110. $this->elementEnd('ul');
  111. $this->elementEnd('fieldset');
  112. }
  113. /**
  114. * Buttons for form actions
  115. *
  116. * Submit and cancel buttons (or whatever)
  117. * Sub-classes should overload this to show their own buttons.
  118. * @return void
  119. */
  120. function formActions()
  121. {
  122. $this->submit('submit', _('Save'));
  123. }
  124. /**
  125. * ID of the form
  126. *
  127. * Should be unique on the page. Sub-classes should overload this
  128. * to show their own IDs.
  129. * @return int ID of the form
  130. */
  131. function id() {
  132. return 'form_choosetheme_prefs';
  133. }
  134. /**
  135. * Action of the form.
  136. *
  137. * URL to post to. Should be overloaded by subclasses to give
  138. * somewhere to post to.
  139. * @return string URL to post to
  140. */
  141. function action() {
  142. return common_local_url('choosethemesettings');
  143. }
  144. /**
  145. * Class of the form. May include space-separated list of multiple classes.
  146. *
  147. * @return string the form's class
  148. */
  149. function formClass() {
  150. return 'form_settings';
  151. }
  152. }