uapplugin.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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 Plugin
  46. * @package StatusNet
  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 $mediumRectangle = null;
  55. public $rectangle = null;
  56. public $leaderboard = null;
  57. public $wideSkyscraper = null;
  58. /**
  59. * Output our dedicated stylesheet
  60. *
  61. * @param Action $action Action being shown
  62. *
  63. * @return boolean hook flag
  64. */
  65. public function onEndShowStylesheets(Action $action)
  66. {
  67. // XXX: allow override by theme
  68. $action->cssLink('css/uap.css', 'base', 'screen, projection, tv');
  69. return true;
  70. }
  71. /**
  72. * Add a medium rectangle ad at the beginning of sidebar
  73. *
  74. * @param Action $action Action being shown
  75. *
  76. * @return boolean hook flag
  77. */
  78. function onStartShowAside(Action $action)
  79. {
  80. if (!is_null($this->mediumRectangle)) {
  81. $action->elementStart('div',
  82. array('id' => 'ad_medium-rectangle',
  83. 'class' => 'ad'));
  84. $this->showMediumRectangle($action);
  85. $action->elementEnd('div');
  86. }
  87. // XXX: Hack to force ads to show on single-notice pages
  88. if (!is_null($this->rectangle) &&
  89. $action->trimmed('action') == 'shownotice') {
  90. $action->elementStart('div', array('id' => 'aside_primary',
  91. 'class' => 'aside'));
  92. if (Event::handle('StartShowSections', array($action))) {
  93. $action->showSections();
  94. Event::handle('EndShowSections', array($action));
  95. }
  96. $action->elementEnd('div');
  97. return false;
  98. }
  99. return true;
  100. }
  101. /**
  102. * Add a leaderboard in the header
  103. *
  104. * @param Action $action Action being shown
  105. *
  106. * @return boolean hook flag
  107. */
  108. function onEndShowHeader($action)
  109. {
  110. if (!is_null($this->leaderboard)) {
  111. $action->elementStart('div',
  112. array('id' => 'ad_leaderboard',
  113. 'class' => 'ad'));
  114. $this->showLeaderboard($action);
  115. $action->elementEnd('div');
  116. }
  117. return true;
  118. }
  119. /**
  120. * Add a rectangle before aside sections
  121. *
  122. * @param Action $action Action being shown
  123. *
  124. * @return boolean hook flag
  125. */
  126. function onStartShowSections(Action $action)
  127. {
  128. if (!is_null($this->rectangle)) {
  129. $action->elementStart('div',
  130. array('id' => 'ad_rectangle',
  131. 'class' => 'ad'));
  132. $this->showRectangle($action);
  133. $action->elementEnd('div');
  134. }
  135. return true;
  136. }
  137. /**
  138. * Add a wide skyscraper after the aside
  139. *
  140. * @param Action $action Action being shown
  141. *
  142. * @return boolean hook flag
  143. */
  144. function onEndShowAside(Action $action)
  145. {
  146. if (!is_null($this->wideSkyscraper)) {
  147. $action->elementStart('div',
  148. array('id' => 'ad_wide-skyscraper',
  149. 'class' => 'ad'));
  150. $this->showWideSkyscraper($action);
  151. $action->elementEnd('div');
  152. }
  153. return true;
  154. }
  155. /**
  156. * Show a medium rectangle ad
  157. *
  158. * @param Action $action Action being shown
  159. *
  160. * @return void
  161. */
  162. abstract protected function showMediumRectangle($action);
  163. /**
  164. * Show a rectangle ad
  165. *
  166. * @param Action $action Action being shown
  167. *
  168. * @return void
  169. */
  170. abstract protected function showRectangle($action);
  171. /**
  172. * Show a wide skyscraper ad
  173. *
  174. * @param Action $action Action being shown
  175. *
  176. * @return void
  177. */
  178. abstract protected function showWideSkyscraper($action);
  179. /**
  180. * Show a leaderboard ad
  181. *
  182. * @param Action $action Action being shown
  183. *
  184. * @return void
  185. */
  186. abstract protected function showLeaderboard($action);
  187. }