forked from GNUsocial/gnu-social
make uapplugin an abstract class
This commit is contained in:
parent
1758ed453b
commit
7c54591472
@ -22,6 +22,7 @@
|
|||||||
* @category Action
|
* @category Action
|
||||||
* @package StatusNet
|
* @package StatusNet
|
||||||
* @author Sarven Capadisli <csarven@status.net>
|
* @author Sarven Capadisli <csarven@status.net>
|
||||||
|
* @author Evan Prodromou <evan@status.net>
|
||||||
* @copyright 2010 StatusNet, Inc.
|
* @copyright 2010 StatusNet, Inc.
|
||||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
||||||
* @link http://status.net/
|
* @link http://status.net/
|
||||||
@ -32,145 +33,155 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Abstract superclass for advertising plugins
|
||||||
|
*
|
||||||
|
* Plugins for showing ads should derive from this plugin.
|
||||||
|
*
|
||||||
* Outputs the following ad types (based on UAP):
|
* Outputs the following ad types (based on UAP):
|
||||||
|
*
|
||||||
* Medium Rectangle 300x250
|
* Medium Rectangle 300x250
|
||||||
* Rectangle 180x150
|
* Rectangle 180x150
|
||||||
* Leaderboard 728x90
|
* Leaderboard 728x90
|
||||||
* Wide Skyscraper 160x600
|
* 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
|
* @category Plugin
|
||||||
* @package StatusNet
|
* @package StatusNet
|
||||||
* @author Sarven Capadisli <csarven@status.net>
|
* @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
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
||||||
* @link http://status.net/
|
* @link http://status.net/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class UAPPlugin extends Plugin
|
abstract class UAPPlugin extends Plugin
|
||||||
{
|
{
|
||||||
public $MediumRectangle = null;
|
public $MediumRectangle = null;
|
||||||
public $Rectangle = null;
|
public $Rectangle = null;
|
||||||
public $Leaderboard = null;
|
public $Leaderboard = null;
|
||||||
public $WideSkyscraper = null;
|
public $WideSkyscraper = null;
|
||||||
|
|
||||||
function __construct($uap = array())
|
/**
|
||||||
{
|
* Output our dedicated stylesheet
|
||||||
$this->uap = $uap;
|
*
|
||||||
|
* @param Action $action Action being shown
|
||||||
parent::__construct();
|
*
|
||||||
}
|
* @return boolean hook flag
|
||||||
|
*/
|
||||||
function onInitializePlugin()
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function onEndShowStatusNetStyles($action)
|
function onEndShowStatusNetStyles($action)
|
||||||
{
|
{
|
||||||
$action->cssLink(common_path('plugins/UAP/uap.css'),
|
// XXX: allow override by theme
|
||||||
null, 'screen, projection, tv');
|
$action->cssLink('css/uap.css', 'base', 'screen, projection, tv');
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//MediumRectangle ad
|
/**
|
||||||
|
* Add a medium rectangle ad at the beginning of sidebar
|
||||||
|
*
|
||||||
|
* @param Action $action Action being shown
|
||||||
|
*
|
||||||
|
* @return boolean hook flag
|
||||||
|
*/
|
||||||
|
|
||||||
function onStartShowAside($action)
|
function onStartShowAside($action)
|
||||||
{
|
{
|
||||||
if (!$this->MediumRectangle) {
|
if (!is_null($this->mediumRectangle)) {
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->showAd($action, array('id' => 'ad_medium-rectangle'),
|
$action->elementStart('div',
|
||||||
$this->MediumRectangle);
|
array('class' => 'ad_medium-rectangle ad'));
|
||||||
|
|
||||||
|
$this->showMediumRectangle($action);
|
||||||
|
|
||||||
|
$action->elementEnd('div');
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
//Rectangle ad
|
* Add a leaderboard and/or rectangle in the header
|
||||||
function onEndShowSiteNotice($action)
|
*
|
||||||
{
|
* @param Action $action Action being shown
|
||||||
if (!$this->Rectangle) {
|
*
|
||||||
return true;
|
* @return boolean hook flag
|
||||||
}
|
*/
|
||||||
|
|
||||||
$this->showAd($action, array('id' => 'ad_rectangle'),
|
|
||||||
$this->Rectangle);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
//Leaderboard and Rectangle ad
|
|
||||||
function onStartShowHeader($action)
|
function onStartShowHeader($action)
|
||||||
{
|
{
|
||||||
if ($this->Leaderboard) {
|
if (!is_null($this->leaderboard)) {
|
||||||
$this->showAd($action, array('id' => 'ad_leaderboard'),
|
$action->elementStart('div',
|
||||||
$this->Leaderboard);
|
array('class' => 'ad_leaderboard ad'));
|
||||||
|
$this->showLeaderboard($action);
|
||||||
|
$action->elementEnd('div');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->Rectangle) {
|
if (!is_null($this->rectangle)) {
|
||||||
$this->showAd($action, array('id' => 'ad_rectangle'),
|
$action->elementStart('div',
|
||||||
$this->Rectangle);
|
array('class' => 'ad_rectangle ad'));
|
||||||
|
$this->showRectangle($action);
|
||||||
|
$action->elementEnd('div');
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//WideSkyscraper ad
|
/**
|
||||||
|
* Add a wide skyscraper after the aside
|
||||||
|
*
|
||||||
|
* @param Action $action Action being shown
|
||||||
|
*
|
||||||
|
* @return boolean hook flag
|
||||||
|
*/
|
||||||
|
|
||||||
function onEndShowAside($action)
|
function onEndShowAside($action)
|
||||||
{
|
{
|
||||||
if (!$this->WideSkyscraper) {
|
if (!is_null($this->wideSkyscraper)) {
|
||||||
return true;
|
$action->elementStart('div',
|
||||||
|
array('class' => 'ad_wide-skyscraper ad'));
|
||||||
|
|
||||||
|
$this->showWideSkyscraper($action);
|
||||||
|
|
||||||
|
$action->elementEnd('div');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->showAd($action, array('id' => 'ad_wide-skyscraper'),
|
|
||||||
$this->WideSkyscraper);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Output ad container
|
/**
|
||||||
function showAd($action, $attr=array(), $value)
|
* Show a medium rectangle ad
|
||||||
{
|
*
|
||||||
$classes = ($attr['class']) ? $attr['class'].' ' : '';
|
* @param Action $action Action being shown
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
|
||||||
$action->elementStart('div', array('id' => $attr['id'],
|
abstract protected function showMediumRectangle($action);
|
||||||
'class' => $classes.'ad'));
|
|
||||||
$action->raw($value);
|
|
||||||
$action->elementEnd('div');
|
|
||||||
}
|
|
||||||
|
|
||||||
function onPluginVersion(&$versions)
|
/**
|
||||||
{
|
* Show a rectangle ad
|
||||||
$versions[] = array('name' => 'UAP',
|
*
|
||||||
'version' => STATUSNET_VERSION,
|
* @param Action $action Action being shown
|
||||||
'author' => 'Sarven Capadisli',
|
*
|
||||||
'homepage' => 'http://status.net/wiki/Plugin:UAP',
|
* @return void
|
||||||
'rawdescription' =>
|
*/
|
||||||
_m('Outputs ad placements based on Universal Ad Package'));
|
|
||||||
return true;
|
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);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user