]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/uapplugin.php
Merge remote branch 'gitorious/master'
[quix0rs-gnu-social.git] / lib / uapplugin.php
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
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
32     exit(1);
33 }
34
35 /**
36  * Abstract superclass for advertising plugins
37  *
38  * Plugins for showing ads should derive from this plugin.
39  *
40  * Outputs the following ad types (based on UAP):
41  *
42  * Medium Rectangle 300x250
43  * Rectangle        180x150
44  * Leaderboard      728x90
45  * Wide Skyscraper  160x600
46  *
47  * @category Plugin
48  * @package  StatusNet
49  * @author   Sarven Capadisli <csarven@status.net>
50  * @author   Evan Prodromou <evan@status.net>
51  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
52  * @link     http://status.net/
53  */
54
55 abstract class UAPPlugin extends Plugin
56 {
57     public $mediumRectangle = null;
58     public $rectangle       = null;
59     public $leaderboard     = null;
60     public $wideSkyscraper  = null;
61
62     /**
63      * Output our dedicated stylesheet
64      *
65      * @param Action $action Action being shown
66      *
67      * @return boolean hook flag
68      */
69
70     function onEndShowStatusNetStyles($action)
71     {
72         // XXX: allow override by theme
73         $action->cssLink('css/uap.css', 'base', 'screen, projection, tv');
74         return true;
75     }
76
77     /**
78      * Add a medium rectangle ad at the beginning of sidebar
79      *
80      * @param Action $action Action being shown
81      *
82      * @return boolean hook flag
83      */
84
85     function onStartShowAside($action)
86     {
87         if (!is_null($this->mediumRectangle)) {
88
89             $action->elementStart('div',
90                                   array('id' => 'ad_medium-rectangle',
91                                         'class' => 'ad'));
92
93             $this->showMediumRectangle($action);
94
95             $action->elementEnd('div');
96         }
97
98         // XXX: Hack to force ads to show on single-notice pages
99
100         if (!is_null($this->rectangle) &&
101             $action->trimmed('action') == 'shownotice') {
102
103             $action->elementStart('div', array('id' => 'aside_primary',
104                                                'class' => 'aside'));
105
106             if (Event::handle('StartShowSections', array($action))) {
107                 $action->showSections();
108                 Event::handle('EndShowSections', array($action));
109             }
110
111             $action->elementEnd('div');
112
113             return false;
114         }
115
116         return true;
117     }
118
119     /**
120      * Add a leaderboard in the header
121      *
122      * @param Action $action Action being shown
123      *
124      * @return boolean hook flag
125      */
126
127     function onEndShowHeader($action)
128     {
129         if (!is_null($this->leaderboard)) {
130             $action->elementStart('div',
131                                   array('id' => 'ad_leaderboard',
132                                         'class' => 'ad'));
133             $this->showLeaderboard($action);
134             $action->elementEnd('div');
135         }
136
137         return true;
138     }
139
140     /**
141      * Add a rectangle before aside sections
142      *
143      * @param Action $action Action being shown
144      *
145      * @return boolean hook flag
146      */
147
148     function onStartShowSections($action)
149     {
150         if (!is_null($this->rectangle)) {
151             $action->elementStart('div',
152                                   array('id' => 'ad_rectangle',
153                                         'class' => 'ad'));
154             $this->showRectangle($action);
155             $action->elementEnd('div');
156         }
157
158         return true;
159     }
160
161     /**
162      * Add a wide skyscraper after the aside
163      *
164      * @param Action $action Action being shown
165      *
166      * @return boolean hook flag
167      */
168
169     function onEndShowAside($action)
170     {
171         if (!is_null($this->wideSkyscraper)) {
172             $action->elementStart('div',
173                                   array('id' => 'ad_wide-skyscraper',
174                                         'class' => 'ad'));
175
176             $this->showWideSkyscraper($action);
177
178             $action->elementEnd('div');
179         }
180         return true;
181     }
182
183     /**
184      * Show a medium rectangle ad
185      *
186      * @param Action $action Action being shown
187      *
188      * @return void
189      */
190
191     abstract protected function showMediumRectangle($action);
192
193     /**
194      * Show a rectangle ad
195      *
196      * @param Action $action Action being shown
197      *
198      * @return void
199      */
200
201     abstract protected function showRectangle($action);
202
203     /**
204      * Show a wide skyscraper ad
205      *
206      * @param Action $action Action being shown
207      *
208      * @return void
209      */
210
211     abstract protected function showWideSkyscraper($action);
212
213     /**
214      * Show a leaderboard ad
215      *
216      * @param Action $action Action being shown
217      *
218      * @return void
219      */
220
221     abstract protected function showLeaderboard($action);
222 }