openxadminpanel.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * OpenX 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 OpenX
  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 openx settings
  34. *
  35. * @category OpenX
  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 OpenXadminpanelAction extends AdminPanelAction
  42. {
  43. /**
  44. * Returns the page title
  45. *
  46. * @return string page title
  47. */
  48. function title()
  49. {
  50. // TRANS: Page title for OpenX admin panel.
  51. return _m('TITLE', 'OpenX');
  52. }
  53. /**
  54. * Instructions for using this form.
  55. *
  56. * @return string instructions
  57. */
  58. function getInstructions()
  59. {
  60. // TRANS: Instructions for OpenX admin panel.
  61. return _m('OpenX 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 OpenXAdminPanelForm($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('openx' => array('adScript', '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 openx admin panel
  107. */
  108. class OpenXAdminPanelForm 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_openx_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_openx';
  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('openxadminpanel');
  136. }
  137. /**
  138. * Data elements of the form
  139. *
  140. * @return void
  141. */
  142. function formData()
  143. {
  144. $this->out->elementStart('fieldset', array('id' => 'openx_admin'));
  145. $this->out->elementStart('ul', 'form_data');
  146. $this->li();
  147. $this->input('adScript',
  148. // TRANS: Form label in OpenX admin panel.
  149. _m('Ad script URL'),
  150. // TRANS: Tooltip for form label in OpenX admin panel.
  151. _m('Script URL'),
  152. 'openx');
  153. $this->unli();
  154. $this->li();
  155. $this->input('mediumRectangle',
  156. // TRANS: Form label in OpenX admin panel. Refers to advertisement format.
  157. _m('Medium rectangle'),
  158. // TRANS: Tooltip for form label in OpenX admin panel. Refers to advertisement format.
  159. _m('Medium rectangle zone'),
  160. 'openx');
  161. $this->unli();
  162. $this->li();
  163. $this->input('rectangle',
  164. // TRANS: Form label in OpenX admin panel. Refers to advertisement format.
  165. _m('Rectangle'),
  166. // TRANS: Tooltip for form label in OpenX admin panel. Refers to advertisement format.
  167. _m('Rectangle zone'),
  168. 'openx');
  169. $this->unli();
  170. $this->li();
  171. $this->input('leaderboard',
  172. // TRANS: Form label in OpenX admin panel. Refers to advertisement format.
  173. _m('Leaderboard'),
  174. // TRANS: Tooltip for form label in OpenX admin panel. Refers to advertisement format.
  175. _m('Leaderboard zone'),
  176. 'openx');
  177. $this->unli();
  178. $this->li();
  179. $this->input('wideSkyscraper',
  180. // TRANS: Form label in OpenX admin panel. Refers to advertisement format.
  181. _m('Skyscraper'),
  182. // TRANS: Tooltip for form label in OpenX admin panel. Refers to advertisement format.
  183. _m('Wide skyscraper zone'),
  184. 'openx');
  185. $this->unli();
  186. $this->out->elementEnd('ul');
  187. }
  188. /**
  189. * Action elements
  190. *
  191. * @return void
  192. */
  193. function formActions()
  194. {
  195. $this->out->submit('submit',
  196. // TRANS: Submit button text in OpenX admin panel.
  197. _m('BUTTON','Save'),
  198. 'submit',
  199. null,
  200. // TRANS: Submit button title in OpenX admin panel.
  201. _m('Save OpenX settings.'));
  202. }
  203. }