* @category Action
* @package StatusNet
* @author Sarven Capadisli <csarven@status.net>
+ * @author Evan Prodromou <evan@status.net>
* @copyright 2010 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
-if (!defined('STATUSNET') && !defined('LACONICA')) {
+if (!defined('STATUSNET')) {
exit(1);
}
/**
+ * Abstract superclass for advertising plugins
+ *
+ * Plugins for showing ads should derive from this plugin.
+ *
* Outputs the following ad types (based on UAP):
+ *
* Medium Rectangle 300x250
* Rectangle 180x150
* Leaderboard 728x90
* Wide Skyscraper 160x600
*
- * Any number of ad types can be used. Enable all using example:
- * addPlugin('UAP', array(
- * 'MediumRectangle' => '<script type="text/javascript">var foo = 1;</script>',
- * 'Rectangle' => '<script type="text/javascript">var bar = 2;</script>',
- * 'Leaderboard' => '<script type="text/javascript">var baz = 2;</script>',
- * 'WideSkyscraper' => '<script type="text/javascript">var bbq = 4;</script>'
- * )
- * );
- *
* @category Plugin
* @package StatusNet
* @author Sarven Capadisli <csarven@status.net>
+ * @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
-
-class UAPPlugin extends Plugin
+abstract class UAPPlugin extends Plugin
{
- public $MediumRectangle = null;
- public $Rectangle = null;
- public $Leaderboard = null;
- public $WideSkyscraper = null;
-
- function __construct($uap = array())
+ public $mediumRectangle = null;
+ public $rectangle = null;
+ public $leaderboard = null;
+ public $wideSkyscraper = null;
+
+ /**
+ * Output our dedicated stylesheet
+ *
+ * @param Action $action Action being shown
+ *
+ * @return boolean hook flag
+ */
+ public function onEndShowStylesheets(Action $action)
{
- $this->uap = $uap;
-
- parent::__construct();
+ // XXX: allow override by theme
+ $action->cssLink('css/uap.css', 'base', 'screen, projection, tv');
+ return true;
}
- function onInitializePlugin()
+ /**
+ * Add a medium rectangle ad at the beginning of sidebar
+ *
+ * @param Action $action Action being shown
+ *
+ * @return boolean hook flag
+ */
+ function onStartShowAside(Action $action)
{
- foreach($this->uap as $key => $value) {
- switch(strtolower($key)) {
- case 'mediumrectangle': default:
- $this->MediumRectangle = $value;
- break;
- case 'rectangle':
- $this->Rectangle = $value;
- break;
- case 'leaderboard':
- $this->Leaderboard = $value;
- break;
- case 'wideskyscraper':
- $this->WideSkyscraper = $value;
- break;
- }
- }
- }
+ if (!is_null($this->mediumRectangle)) {
- function onEndShowStatusNetStyles($action)
- {
- $action->cssLink(common_path('plugins/UAP/uap.css'),
- null, 'screen, projection, tv');
- return true;
- }
+ $action->elementStart('div',
+ array('id' => 'ad_medium-rectangle',
+ 'class' => 'ad'));
- //MediumRectangle ad
- function onStartShowAside($action)
- {
- if (!$this->MediumRectangle) {
- return true;
+ $this->showMediumRectangle($action);
+
+ $action->elementEnd('div');
}
- $this->showAd($action, array('id' => 'ad_medium-rectangle'),
- $this->MediumRectangle);
+ // XXX: Hack to force ads to show on single-notice pages
- return true;
- }
+ if (!is_null($this->rectangle) &&
+ $action->trimmed('action') == 'shownotice') {
-/*
- //Rectangle ad
- function onEndShowSiteNotice($action)
- {
- if (!$this->Rectangle) {
- return true;
- }
+ $action->elementStart('div', array('id' => 'aside_primary',
+ 'class' => 'aside'));
- $this->showAd($action, array('id' => 'ad_rectangle'),
- $this->Rectangle);
+ if (Event::handle('StartShowSections', array($action))) {
+ $action->showSections();
+ Event::handle('EndShowSections', array($action));
+ }
+
+ $action->elementEnd('div');
+
+ return false;
+ }
return true;
}
-*/
- //Leaderboard and Rectangle ad
- function onStartShowHeader($action)
- {
- if ($this->Leaderboard) {
- $this->showAd($action, array('id' => 'ad_leaderboard'),
- $this->Leaderboard);
- }
+ /**
+ * Add a leaderboard in the header
+ *
+ * @param Action $action Action being shown
+ *
+ * @return boolean hook flag
+ */
- if ($this->Rectangle) {
- $this->showAd($action, array('id' => 'ad_rectangle'),
- $this->Rectangle);
+ function onEndShowHeader($action)
+ {
+ if (!is_null($this->leaderboard)) {
+ $action->elementStart('div',
+ array('id' => 'ad_leaderboard',
+ 'class' => 'ad'));
+ $this->showLeaderboard($action);
+ $action->elementEnd('div');
}
return true;
}
- //WideSkyscraper ad
- function onEndShowAside($action)
+ /**
+ * Add a rectangle before aside sections
+ *
+ * @param Action $action Action being shown
+ *
+ * @return boolean hook flag
+ */
+ function onStartShowSections(Action $action)
{
- if (!$this->WideSkyscraper) {
- return true;
+ if (!is_null($this->rectangle)) {
+ $action->elementStart('div',
+ array('id' => 'ad_rectangle',
+ 'class' => 'ad'));
+ $this->showRectangle($action);
+ $action->elementEnd('div');
}
- $this->showAd($action, array('id' => 'ad_wide-skyscraper'),
- $this->WideSkyscraper);
-
return true;
}
- //Output ad container
- function showAd($action, $attr=array(), $value)
+ /**
+ * Add a wide skyscraper after the aside
+ *
+ * @param Action $action Action being shown
+ *
+ * @return boolean hook flag
+ */
+ function onEndShowAside(Action $action)
{
- $classes = ($attr['class']) ? $attr['class'].' ' : '';
+ if (!is_null($this->wideSkyscraper)) {
+ $action->elementStart('div',
+ array('id' => 'ad_wide-skyscraper',
+ 'class' => 'ad'));
- $action->elementStart('div', array('id' => $attr['id'],
- 'class' => $classes.'ad'));
- $action->raw($value);
- $action->elementEnd('div');
- }
+ $this->showWideSkyscraper($action);
- function onPluginVersion(&$versions)
- {
- $versions[] = array('name' => 'UAP',
- 'version' => STATUSNET_VERSION,
- 'author' => 'Sarven Capadisli',
- 'homepage' => 'http://status.net/wiki/Plugin:UAP',
- 'rawdescription' =>
- _m('Outputs ad placements based on Universal Ad Package'));
+ $action->elementEnd('div');
+ }
return true;
}
+
+ /**
+ * Show a medium rectangle ad
+ *
+ * @param Action $action Action being shown
+ *
+ * @return void
+ */
+ abstract protected function showMediumRectangle($action);
+
+ /**
+ * Show a rectangle ad
+ *
+ * @param Action $action Action being shown
+ *
+ * @return void
+ */
+ abstract protected function showRectangle($action);
+
+ /**
+ * Show a wide skyscraper ad
+ *
+ * @param Action $action Action being shown
+ *
+ * @return void
+ */
+ abstract protected function showWideSkyscraper($action);
+
+ /**
+ * Show a leaderboard ad
+ *
+ * @param Action $action Action being shown
+ *
+ * @return void
+ */
+ abstract protected function showLeaderboard($action);
}