git.gnu.io has moved to IP address 209.51.188.249 -- please double check where you are logging in.

uapplugin.php 5.69 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
<?php
/**
 * StatusNet, the distributed open-source microblogging tool
 *
 * UAP (Universal Ad Package) plugin
 *
 * PHP version 5
 *
 * LICENCE: This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @category  Action
 * @package   StatusNet
 * @author    Sarven Capadisli <csarven@status.net>
25
 * @author    Evan Prodromou <evan@status.net>
26 27 28 29 30
 * @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/
 */

31
if (!defined('STATUSNET')) {
32 33 34 35
    exit(1);
}

/**
36 37 38 39
 * Abstract superclass for advertising plugins
 *
 * Plugins for showing ads should derive from this plugin.
 *
40
 * Outputs the following ad types (based on UAP):
41
 *
42 43 44 45 46 47 48 49
 * Medium Rectangle 300x250
 * Rectangle        180x150
 * Leaderboard      728x90
 * Wide Skyscraper  160x600
 *
 * @category Plugin
 * @package  StatusNet
 * @author   Sarven Capadisli <csarven@status.net>
50
 * @author   Evan Prodromou <evan@status.net>
51 52 53
 * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
 * @link     http://status.net/
 */
54
abstract class UAPPlugin extends Plugin
55
{
56 57 58 59
    public $mediumRectangle = null;
    public $rectangle       = null;
    public $leaderboard     = null;
    public $wideSkyscraper  = null;
60 61 62 63 64 65 66 67

    /**
     * Output our dedicated stylesheet
     *
     * @param Action $action Action being shown
     *
     * @return boolean hook flag
     */
68
    public function onEndShowStylesheets(Action $action)
69
    {
70 71
        // XXX: allow override by theme
        $action->cssLink('css/uap.css', 'base', 'screen, projection, tv');
72 73 74
        return true;
    }

75 76 77 78 79 80 81
    /**
     * Add a medium rectangle ad at the beginning of sidebar
     *
     * @param Action $action Action being shown
     *
     * @return boolean hook flag
     */
82
    function onStartShowAside(Action $action)
83
    {
84
        if (!is_null($this->mediumRectangle)) {
85

86
            $action->elementStart('div',
87 88
                                  array('id' => 'ad_medium-rectangle',
                                        'class' => 'ad'));
89

90
            $this->showMediumRectangle($action);
91

92
            $action->elementEnd('div');
93 94
        }

95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
        // XXX: Hack to force ads to show on single-notice pages

        if (!is_null($this->rectangle) &&
            $action->trimmed('action') == 'shownotice') {

            $action->elementStart('div', array('id' => 'aside_primary',
                                               'class' => 'aside'));

            if (Event::handle('StartShowSections', array($action))) {
                $action->showSections();
                Event::handle('EndShowSections', array($action));
            }

            $action->elementEnd('div');

            return false;
        }

113 114 115
        return true;
    }

116
    /**
117
     * Add a leaderboard in the header
118 119 120 121 122 123
     *
     * @param Action $action Action being shown
     *
     * @return boolean hook flag
     */

124
    function onEndShowHeader($action)
125
    {
126 127
        if (!is_null($this->leaderboard)) {
            $action->elementStart('div',
128 129
                                  array('id' => 'ad_leaderboard',
                                        'class' => 'ad'));
130 131
            $this->showLeaderboard($action);
            $action->elementEnd('div');
132 133
        }

134 135 136 137 138 139 140 141 142 143
        return true;
    }

    /**
     * Add a rectangle before aside sections
     *
     * @param Action $action Action being shown
     *
     * @return boolean hook flag
     */
144
    function onStartShowSections(Action $action)
145
    {
146 147
        if (!is_null($this->rectangle)) {
            $action->elementStart('div',
148 149
                                  array('id' => 'ad_rectangle',
                                        'class' => 'ad'));
150 151
            $this->showRectangle($action);
            $action->elementEnd('div');
152 153 154 155 156
        }

        return true;
    }

157 158 159 160 161 162 163
    /**
     * Add a wide skyscraper after the aside
     *
     * @param Action $action Action being shown
     *
     * @return boolean hook flag
     */
164
    function onEndShowAside(Action $action)
165
    {
166 167
        if (!is_null($this->wideSkyscraper)) {
            $action->elementStart('div',
168 169
                                  array('id' => 'ad_wide-skyscraper',
                                        'class' => 'ad'));
170

171
            $this->showWideSkyscraper($action);
172

173 174
            $action->elementEnd('div');
        }
175 176 177
        return true;
    }

178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
    /**
     * 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);
213
}