UAPPlugin.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * UAP (Universal Ad Package) plugin
  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 Action
  23. * @package StatusNet
  24. * @author Sarven Capadisli <csarven@status.net>
  25. * @author Evan Prodromou <evan@status.net>
  26. * @copyright 2010 StatusNet, Inc.
  27. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  28. * @link http://status.net/
  29. */
  30. if (!defined('STATUSNET')) {
  31. exit(1);
  32. }
  33. /**
  34. * Abstract superclass for advertising plugins
  35. *
  36. * Plugins for showing ads should derive from this plugin.
  37. *
  38. * Outputs the following ad types (based on UAP):
  39. *
  40. * Medium Rectangle 300x250
  41. * Rectangle 180x150
  42. * Leaderboard 728x90
  43. * Wide Skyscraper 160x600
  44. *
  45. * @category Module
  46. * @package GNUsocial
  47. * @author Sarven Capadisli <csarven@status.net>
  48. * @author Evan Prodromou <evan@status.net>
  49. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  50. * @link http://status.net/
  51. */
  52. abstract class UAPPlugin extends Plugin
  53. {
  54. public $widgetOpts;
  55. public $scoped;
  56. public $mediumRectangle = null;
  57. public $rectangle = null;
  58. public $leaderboard = null;
  59. public $wideSkyscraper = null;
  60. /**
  61. * Output our dedicated stylesheet
  62. *
  63. * @param Action $action Action being shown
  64. *
  65. * @return boolean hook flag
  66. */
  67. public function onEndShowStylesheets(Action $action)
  68. {
  69. // XXX: allow override by theme
  70. $action->cssLink('css/uap.css', 'base', 'screen, projection, tv');
  71. return true;
  72. }
  73. /**
  74. * Add a medium rectangle ad at the beginning of sidebar
  75. *
  76. * @param Action $action Action being shown
  77. *
  78. * @return boolean hook flag
  79. */
  80. function onStartShowAside(Action $action)
  81. {
  82. if (!is_null($this->mediumRectangle)) {
  83. $action->elementStart('div',
  84. array('id' => 'ad_medium-rectangle',
  85. 'class' => 'ad'));
  86. $this->showMediumRectangle($action);
  87. $action->elementEnd('div');
  88. }
  89. // XXX: Hack to force ads to show on single-notice pages
  90. if (!is_null($this->rectangle) &&
  91. $action->trimmed('action') == 'shownotice') {
  92. $action->elementStart('div', array('id' => 'aside_primary',
  93. 'class' => 'aside'));
  94. if (Event::handle('StartShowSections', array($action))) {
  95. $action->showSections();
  96. Event::handle('EndShowSections', array($action));
  97. }
  98. $action->elementEnd('div');
  99. return false;
  100. }
  101. return true;
  102. }
  103. /**
  104. * Add a leaderboard in the header
  105. *
  106. * @param Action $action Action being shown
  107. *
  108. * @return boolean hook flag
  109. */
  110. function onEndShowHeader($action)
  111. {
  112. if (!is_null($this->leaderboard)) {
  113. $action->elementStart('div',
  114. array('id' => 'ad_leaderboard',
  115. 'class' => 'ad'));
  116. $this->showLeaderboard($action);
  117. $action->elementEnd('div');
  118. }
  119. return true;
  120. }
  121. /**
  122. * Add a rectangle before aside sections
  123. *
  124. * @param Action $action Action being shown
  125. *
  126. * @return boolean hook flag
  127. */
  128. function onStartShowSections(Action $action)
  129. {
  130. if (!is_null($this->rectangle)) {
  131. $action->elementStart('div',
  132. array('id' => 'ad_rectangle',
  133. 'class' => 'ad'));
  134. $this->showRectangle($action);
  135. $action->elementEnd('div');
  136. }
  137. return true;
  138. }
  139. /**
  140. * Add a wide skyscraper after the aside
  141. *
  142. * @param Action $action Action being shown
  143. *
  144. * @return boolean hook flag
  145. */
  146. function onEndShowAside(Action $action)
  147. {
  148. if (!is_null($this->wideSkyscraper)) {
  149. $action->elementStart('div',
  150. array('id' => 'ad_wide-skyscraper',
  151. 'class' => 'ad'));
  152. $this->showWideSkyscraper($action);
  153. $action->elementEnd('div');
  154. }
  155. return true;
  156. }
  157. /**
  158. * Show a medium rectangle ad
  159. *
  160. * @param Action $action Action being shown
  161. *
  162. * @return void
  163. */
  164. abstract protected function showMediumRectangle($action);
  165. /**
  166. * Show a rectangle ad
  167. *
  168. * @param Action $action Action being shown
  169. *
  170. * @return void
  171. */
  172. abstract protected function showRectangle($action);
  173. /**
  174. * Show a wide skyscraper ad
  175. *
  176. * @param Action $action Action being shown
  177. *
  178. * @return void
  179. */
  180. abstract protected function showWideSkyscraper($action);
  181. /**
  182. * Show a leaderboard ad
  183. *
  184. * @param Action $action Action being shown
  185. *
  186. * @return void
  187. */
  188. abstract protected function showLeaderboard($action);
  189. }