adsenseadminpanel.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Adsense 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 Adsense
  23. * @package StatusNet
  24. * @author Evan Prodromou <evan@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 adsense settings
  34. *
  35. * @category Adsense
  36. * @package StatusNet
  37. * @author Evan Prodromou <evan@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 AdsenseadminpanelAction extends AdminPanelAction
  42. {
  43. /**
  44. * Returns the page title
  45. *
  46. * @return string page title
  47. */
  48. function title()
  49. {
  50. // TRANS: Title of AdSense administrator panel.
  51. return _m('TITLE', 'AdSense');
  52. }
  53. /**
  54. * Instructions for using this form.
  55. *
  56. * @return string instructions
  57. */
  58. function getInstructions()
  59. {
  60. // TRANS: Instructions for AdSense administrator panel.
  61. return _m('AdSense settings for this StatusNet site');
  62. }
  63. /**
  64. * Show the site admin panel form
  65. *
  66. * @return void
  67. */
  68. function showForm()
  69. {
  70. $form = new AdsenseAdminPanelForm($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('adsense' => array('adScript', 'client', 'mediumRectangle', 'rectangle', 'leaderboard', 'wideSkyscraper'));
  82. $values = array();
  83. foreach ($settings as $section => $parts) {
  84. foreach ($parts as $setting) {
  85. $values[$section][$setting] = $this->trimmed($setting);
  86. }
  87. }
  88. // This throws an exception on validation errors
  89. $this->validate($values);
  90. // assert(all values are valid);
  91. $config = new Config();
  92. $config->query('BEGIN');
  93. foreach ($settings as $section => $parts) {
  94. foreach ($parts as $setting) {
  95. Config::save($section, $setting, $values[$section][$setting]);
  96. }
  97. }
  98. $config->query('COMMIT');
  99. return;
  100. }
  101. function validate(&$values)
  102. {
  103. }
  104. }
  105. /**
  106. * Form for the adsense admin panel
  107. */
  108. class AdsenseAdminPanelForm extends AdminForm
  109. {
  110. /**
  111. * ID of the form
  112. *
  113. * @return int ID of the form
  114. */
  115. function id()
  116. {
  117. return 'form_adsense_admin_panel';
  118. }
  119. /**
  120. * class of the form
  121. *
  122. * @return string class of the form
  123. */
  124. function formClass()
  125. {
  126. return 'form_adsense';
  127. }
  128. /**
  129. * Action of the form
  130. *
  131. * @return string URL of the action
  132. */
  133. function action()
  134. {
  135. return common_local_url('adsenseadminpanel');
  136. }
  137. /**
  138. * Data elements of the form
  139. *
  140. * @return void
  141. */
  142. function formData()
  143. {
  144. $this->out->elementStart('fieldset', array('id' => 'adsense_admin'));
  145. $this->out->elementStart('ul', 'form_data');
  146. $this->li();
  147. $this->input('client',
  148. // TRANS: Field label in AdSense administration panel.
  149. _m('Client ID'),
  150. // TRANS: Field title in AdSense administration panel.
  151. _m('Google client ID.'),
  152. 'adsense');
  153. $this->unli();
  154. $this->li();
  155. $this->input('adScript',
  156. // TRANS: Field label in AdSense administration panel.
  157. _m('Ad script URL'),
  158. // TRANS: Field title in AdSense administration panel.
  159. _m('Script URL (advanced).'),
  160. 'adsense');
  161. $this->unli();
  162. $this->li();
  163. $this->input('mediumRectangle',
  164. // TRANS: Field label in AdSense administration panel.
  165. _m('Medium rectangle'),
  166. // TRANS: Field title in AdSense administration panel.
  167. _m('Medium rectangle slot code.'),
  168. 'adsense');
  169. $this->unli();
  170. $this->li();
  171. $this->input('rectangle',
  172. // TRANS: Field label in AdSense administration panel.
  173. _m('Rectangle'),
  174. // TRANS: Field title in AdSense administration panel.
  175. _m('Rectangle slot code.'),
  176. 'adsense');
  177. $this->unli();
  178. $this->li();
  179. $this->input('leaderboard',
  180. // TRANS: Field label in AdSense administration panel.
  181. _m('Leaderboard'),
  182. // TRANS: Field title in AdSense administration panel.
  183. _m('Leaderboard slot code.'),
  184. 'adsense');
  185. $this->unli();
  186. $this->li();
  187. $this->input('wideSkyscraper',
  188. // TRANS: Field label in AdSense administration panel.
  189. _m('Skyscraper'),
  190. // TRANS: Field title in AdSense administration panel.
  191. _m('Wide skyscraper slot code.'),
  192. 'adsense');
  193. $this->unli();
  194. $this->out->elementEnd('ul');
  195. }
  196. /**
  197. * Action elements
  198. *
  199. * @return void
  200. */
  201. function formActions()
  202. {
  203. // TRANS: Button text to save settings in AdSense administration panel.
  204. $this->out->submit('submit', _m('BUTTON','Save'),
  205. // TRANS: Button title to save settings in AdSense administration panel.
  206. 'submit', null, _m('Save AdSense settings.'));
  207. }
  208. }