X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fuapplugin.php;h=ef35bafbfb0fabce891c3439320d8d78438f2f68;hb=ddf3614c843bcd8d9ecfd0850ac9a8cefae6dbba;hp=f3b16548d25f43241f1c3b8d356cc82762058527;hpb=1758ed453bcf2abd11bc2fde8768632099fe0de3;p=quix0rs-gnu-social.git diff --git a/lib/uapplugin.php b/lib/uapplugin.php index f3b16548d2..ef35bafbfb 100644 --- a/lib/uapplugin.php +++ b/lib/uapplugin.php @@ -22,6 +22,7 @@ * @category Action * @package StatusNet * @author Sarven Capadisli + * @author Evan Prodromou * @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/ @@ -32,145 +33,172 @@ 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): + * * 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' => '', - * 'Rectangle' => '', - * 'Leaderboard' => '', - * 'WideSkyscraper' => '' - * ) - * ); - * * @category Plugin * @package StatusNet * @author Sarven Capadisli + * @author Evan Prodromou * @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()) - { - $this->uap = $uap; - - parent::__construct(); - } - - 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; - } - } - } + 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 + */ function onEndShowStatusNetStyles($action) { - $action->cssLink(common_path('plugins/UAP/uap.css'), - null, 'screen, projection, tv'); + // XXX: allow override by theme + $action->cssLink('css/uap.css', 'base', 'screen, projection, tv'); 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) { - if (!$this->MediumRectangle) { - return true; - } + if (!is_null($this->mediumRectangle)) { - $this->showAd($action, array('id' => 'ad_medium-rectangle'), - $this->MediumRectangle); + $action->elementStart('div', + array('id' => 'ad_medium-rectangle', + 'class' => 'ad')); - return true; - } + $this->showMediumRectangle($action); -/* - //Rectangle ad - function onEndShowSiteNotice($action) - { - if (!$this->Rectangle) { - return true; + $action->elementEnd('div'); } - $this->showAd($action, array('id' => 'ad_rectangle'), - $this->Rectangle); - 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) { - 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) { - $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); }