]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/uapplugin.php
Merge commit 'refs/merge-requests/41' of https://gitorious.org/social/mainline into...
[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')) {
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 abstract class UAPPlugin extends Plugin
55 {
56     public $mediumRectangle = null;
57     public $rectangle       = null;
58     public $leaderboard     = null;
59     public $wideSkyscraper  = null;
60
61     /**
62      * Output our dedicated stylesheet
63      *
64      * @param Action $action Action being shown
65      *
66      * @return boolean hook flag
67      */
68     public function onEndShowStylesheets(Action $action)
69     {
70         // XXX: allow override by theme
71         $action->cssLink('css/uap.css', 'base', 'screen, projection, tv');
72         return true;
73     }
74
75     /**
76      * Add a medium rectangle ad at the beginning of sidebar
77      *
78      * @param Action $action Action being shown
79      *
80      * @return boolean hook flag
81      */
82     function onStartShowAside(Action $action)
83     {
84         if (!is_null($this->mediumRectangle)) {
85
86             $action->elementStart('div',
87                                   array('id' => 'ad_medium-rectangle',
88                                         'class' => 'ad'));
89
90             $this->showMediumRectangle($action);
91
92             $action->elementEnd('div');
93         }
94
95         // XXX: Hack to force ads to show on single-notice pages
96
97         if (!is_null($this->rectangle) &&
98             $action->trimmed('action') == 'shownotice') {
99
100             $action->elementStart('div', array('id' => 'aside_primary',
101                                                'class' => 'aside'));
102
103             if (Event::handle('StartShowSections', array($action))) {
104                 $action->showSections();
105                 Event::handle('EndShowSections', array($action));
106             }
107
108             $action->elementEnd('div');
109
110             return false;
111         }
112
113         return true;
114     }
115
116     /**
117      * Add a leaderboard in the header
118      *
119      * @param Action $action Action being shown
120      *
121      * @return boolean hook flag
122      */
123
124     function onEndShowHeader($action)
125     {
126         if (!is_null($this->leaderboard)) {
127             $action->elementStart('div',
128                                   array('id' => 'ad_leaderboard',
129                                         'class' => 'ad'));
130             $this->showLeaderboard($action);
131             $action->elementEnd('div');
132         }
133
134         return true;
135     }
136
137     /**
138      * Add a rectangle before aside sections
139      *
140      * @param Action $action Action being shown
141      *
142      * @return boolean hook flag
143      */
144     function onStartShowSections(Action $action)
145     {
146         if (!is_null($this->rectangle)) {
147             $action->elementStart('div',
148                                   array('id' => 'ad_rectangle',
149                                         'class' => 'ad'));
150             $this->showRectangle($action);
151             $action->elementEnd('div');
152         }
153
154         return true;
155     }
156
157     /**
158      * Add a wide skyscraper after the aside
159      *
160      * @param Action $action Action being shown
161      *
162      * @return boolean hook flag
163      */
164     function onEndShowAside(Action $action)
165     {
166         if (!is_null($this->wideSkyscraper)) {
167             $action->elementStart('div',
168                                   array('id' => 'ad_wide-skyscraper',
169                                         'class' => 'ad'));
170
171             $this->showWideSkyscraper($action);
172
173             $action->elementEnd('div');
174         }
175         return true;
176     }
177
178     /**
179      * Show a medium rectangle ad
180      *
181      * @param Action $action Action being shown
182      *
183      * @return void
184      */
185     abstract protected function showMediumRectangle($action);
186
187     /**
188      * Show a rectangle ad
189      *
190      * @param Action $action Action being shown
191      *
192      * @return void
193      */
194     abstract protected function showRectangle($action);
195
196     /**
197      * Show a wide skyscraper ad
198      *
199      * @param Action $action Action being shown
200      *
201      * @return void
202      */
203     abstract protected function showWideSkyscraper($action);
204
205     /**
206      * Show a leaderboard ad
207      *
208      * @param Action $action Action being shown
209      *
210      * @return void
211      */
212     abstract protected function showLeaderboard($action);
213 }