facebookadminpanel.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Facebook integration administration panel
  6. *
  7. * PHP version 5
  8. *
  9. * LICENCE: This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. * @category Settings
  23. * @package StatusNet
  24. * @author Zach Copley <zach@status.net>
  25. * @copyright 2010 StatusNet, Inc.
  26. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  27. * @link http://status.net/
  28. */
  29. if (!defined('STATUSNET')) {
  30. exit(1);
  31. }
  32. /**
  33. * Administer global Facebook integration settings
  34. *
  35. * @category Admin
  36. * @package StatusNet
  37. * @author Zach Copley <zach@status.net>
  38. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  39. * @link http://status.net/
  40. */
  41. class FacebookadminpanelAction extends AdminPanelAction
  42. {
  43. /**
  44. * Returns the page title
  45. *
  46. * @return string page title
  47. */
  48. function title()
  49. {
  50. // TRANS: Title for Facebook administration panel.
  51. return _m('TITLE','Facebook integration settings');
  52. }
  53. /**
  54. * Instructions for using this form.
  55. *
  56. * @return string instructions
  57. */
  58. function getInstructions()
  59. {
  60. // TRANS: Instruction for Facebook administration panel.
  61. return _m('Facebook integration settings');
  62. }
  63. /**
  64. * Show the Facebook admin panel form
  65. *
  66. * @return void
  67. */
  68. function showForm()
  69. {
  70. $form = new FacebookAdminPanelForm($this);
  71. $form->show();
  72. return;
  73. }
  74. /**
  75. * Save settings from the form
  76. *
  77. * @return void
  78. */
  79. function saveSettings()
  80. {
  81. static $settings = array(
  82. 'facebook' => array('appid', 'secret'),
  83. );
  84. $values = array();
  85. foreach ($settings as $section => $parts) {
  86. foreach ($parts as $setting) {
  87. $values[$section][$setting]
  88. = $this->trimmed($setting);
  89. }
  90. }
  91. // This throws an exception on validation errors
  92. $this->validate($values);
  93. // assert(all values are valid);
  94. $config = new Config();
  95. $config->query('BEGIN');
  96. foreach ($settings as $section => $parts) {
  97. foreach ($parts as $setting) {
  98. Config::save($section, $setting, $values[$section][$setting]);
  99. }
  100. }
  101. $config->query('COMMIT');
  102. return;
  103. }
  104. function validate(&$values)
  105. {
  106. // appId, key and secret (can't be too long)
  107. if (mb_strlen($values['facebook']['appid']) > 255) {
  108. $this->clientError(
  109. // TRANS: Client error displayed when providing too long a Facebook application ID.
  110. _m("Invalid Facebook ID. Maximum length is 255 characters.")
  111. );
  112. }
  113. if (mb_strlen($values['facebook']['secret']) > 255) {
  114. $this->clientError(
  115. // TRANS: Client error displayed when providing too long a Facebook secret key.
  116. _m("Invalid Facebook secret. Maximum length is 255 characters.")
  117. );
  118. }
  119. }
  120. }
  121. class FacebookAdminPanelForm extends AdminForm
  122. {
  123. /**
  124. * ID of the form
  125. *
  126. * @return int ID of the form
  127. */
  128. function id()
  129. {
  130. return 'facebookadminpanel';
  131. }
  132. /**
  133. * class of the form
  134. *
  135. * @return string class of the form
  136. */
  137. function formClass()
  138. {
  139. return 'form_settings';
  140. }
  141. /**
  142. * Action of the form
  143. *
  144. * @return string URL of the action
  145. */
  146. function action()
  147. {
  148. return common_local_url('facebookadminpanel');
  149. }
  150. /**
  151. * Data elements of the form
  152. *
  153. * @return void
  154. */
  155. function formData()
  156. {
  157. $this->out->elementStart(
  158. 'fieldset',
  159. array('id' => 'settings_facebook-application')
  160. );
  161. // TRANS: Fieldset legend.
  162. $this->out->element('legend', null, _m('Facebook application settings'));
  163. $this->out->elementStart('ul', 'form_data');
  164. $this->li();
  165. $this->input(
  166. 'appid',
  167. // TRANS: Field label for Facebook application ID.
  168. _m('Application ID'),
  169. // TRANS: Field title for Facebook application ID.
  170. _m('ID of your Facebook application.'),
  171. 'facebook'
  172. );
  173. $this->unli();
  174. $this->li();
  175. $this->input(
  176. 'secret',
  177. // TRANS: Field label for Facebook secret key.
  178. _m('Secret'),
  179. // TRANS: Field title for Facebook secret key.
  180. _m('Application secret.'),
  181. 'facebook'
  182. );
  183. $this->unli();
  184. $this->out->elementEnd('ul');
  185. $this->out->elementEnd('fieldset');
  186. }
  187. /**
  188. * Action elements
  189. *
  190. * @return void
  191. */
  192. function formActions()
  193. {
  194. // TRANS: Button text to save Facebook integration settings.
  195. $this->out->submit('submit', _m('BUTTON','Save'),
  196. // TRANS: Button title to save Facebook integration settings.
  197. 'submit', null, _m('Save Facebook settings.'));
  198. }
  199. }