sitemapadminpanel.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. * Sitemap administration panel
  18. *
  19. * @category Sitemap
  20. * @package GNUsocial
  21. * @author Evan Prodromou <evan@status.net>
  22. * @copyright 2010 StatusNet, Inc.
  23. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  24. */
  25. defined('GNUSOCIAL') || die();
  26. /**
  27. * Administer sitemap settings
  28. *
  29. * @category Sitemap
  30. * @package GNUsocial
  31. * @author Evan Prodromou <evan@status.net>
  32. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  33. */
  34. class SitemapadminpanelAction extends AdminPanelAction
  35. {
  36. /**
  37. * Returns the page title
  38. *
  39. * @return string page title
  40. */
  41. public function title()
  42. {
  43. // TRANS: Title for sitemap.
  44. return _m('Sitemap');
  45. }
  46. /**
  47. * Instructions for using this form.
  48. *
  49. * @return string instructions
  50. */
  51. public function getInstructions()
  52. {
  53. // TRANS: Instructions for sitemap.
  54. return _m('Sitemap settings for this StatusNet site');
  55. }
  56. /**
  57. * Show the site admin panel form
  58. *
  59. * @return void
  60. */
  61. public function showForm()
  62. {
  63. $form = new SitemapAdminPanelForm($this);
  64. $form->show();
  65. return;
  66. }
  67. /**
  68. * Save settings from the form
  69. *
  70. * @return void
  71. */
  72. public function saveSettings()
  73. {
  74. static $settings = array('sitemap' => array('yahookey', 'bingkey'));
  75. $values = array();
  76. foreach ($settings as $section => $parts) {
  77. foreach ($parts as $setting) {
  78. $values[$section][$setting] = $this->trimmed($setting);
  79. }
  80. }
  81. // This throws an exception on validation errors
  82. $this->validate($values);
  83. // assert(all values are valid);
  84. $config = new Config();
  85. $config->query('START TRANSACTION');
  86. foreach ($settings as $section => $parts) {
  87. foreach ($parts as $setting) {
  88. Config::save($section, $setting, $values[$section][$setting]);
  89. }
  90. }
  91. $config->query('COMMIT');
  92. return;
  93. }
  94. public function validate(&$values)
  95. {
  96. }
  97. }
  98. /**
  99. * Form for the sitemap admin panel
  100. */
  101. class SitemapAdminPanelForm extends AdminForm
  102. {
  103. /**
  104. * ID of the form
  105. *
  106. * @return int ID of the form
  107. */
  108. public function id()
  109. {
  110. return 'form_sitemap_admin_panel';
  111. }
  112. /**
  113. * class of the form
  114. *
  115. * @return string class of the form
  116. */
  117. public function formClass()
  118. {
  119. return 'form_sitemap';
  120. }
  121. /**
  122. * Action of the form
  123. *
  124. * @return string URL of the action
  125. */
  126. public function action()
  127. {
  128. return common_local_url('sitemapadminpanel');
  129. }
  130. /**
  131. * Data elements of the form
  132. *
  133. * @return void
  134. */
  135. public function formData()
  136. {
  137. $this->out->elementStart('ul', 'form_data');
  138. $this->li();
  139. $this->input(
  140. 'yahookey',
  141. // TRANS: Field label.
  142. _m('Yahoo key'),
  143. // TRANS: Title for field label.
  144. _m('Yahoo! Site Explorer verification key.'),
  145. 'sitemap'
  146. );
  147. $this->unli();
  148. $this->li();
  149. $this->input(
  150. 'bingkey',
  151. // TRANS: Field label.
  152. _m('Bing key'),
  153. // TRANS: Title for field label.
  154. _m('Bing Webmaster Tools verification key.'),
  155. 'sitemap'
  156. );
  157. $this->unli();
  158. $this->out->elementEnd('ul');
  159. }
  160. /**
  161. * Action elements
  162. *
  163. * @return void
  164. */
  165. public function formActions()
  166. {
  167. $this->out->submit(
  168. 'submit',
  169. // TRANS: Submit button text to save sitemap settings.
  170. _m('BUTTON', 'Save'),
  171. 'submit',
  172. null,
  173. // TRANS: Submit button title to save sitemap settings.
  174. _m('Save sitemap settings.')
  175. );
  176. }
  177. }