]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/uapplugin.php
move UAP plugin to core
[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  * @copyright 2010 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://status.net/
28  */
29
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
31     exit(1);
32 }
33
34 /**
35  * Outputs the following ad types (based on UAP):
36  * Medium Rectangle 300x250
37  * Rectangle        180x150
38  * Leaderboard      728x90
39  * Wide Skyscraper  160x600
40  *
41  * Any number of ad types can be used. Enable all using example:
42  * addPlugin('UAP', array(
43  *  'MediumRectangle' => '<script type="text/javascript">var foo = 1;</script>',
44  *  'Rectangle' => '<script type="text/javascript">var bar = 2;</script>',
45  *  'Leaderboard' => '<script type="text/javascript">var baz = 2;</script>',
46  *  'WideSkyscraper' => '<script type="text/javascript">var bbq = 4;</script>'
47  *  )
48  * );
49  *
50  * @category Plugin
51  * @package  StatusNet
52  * @author   Sarven Capadisli <csarven@status.net>
53  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
54  * @link     http://status.net/
55  */
56
57 class UAPPlugin extends Plugin
58 {
59     public $MediumRectangle = null;
60     public $Rectangle = null;
61     public $Leaderboard = null;
62     public $WideSkyscraper = null;
63
64     function __construct($uap = array())
65     {
66         $this->uap = $uap;
67
68         parent::__construct();
69     }
70
71     function onInitializePlugin()
72     {
73         foreach($this->uap as $key => $value) {
74             switch(strtolower($key)) {
75                 case 'mediumrectangle': default:
76                     $this->MediumRectangle = $value;
77                     break;
78                 case 'rectangle':
79                     $this->Rectangle = $value;
80                     break;
81                 case 'leaderboard':
82                     $this->Leaderboard = $value;
83                     break;
84                 case 'wideskyscraper':
85                     $this->WideSkyscraper = $value;
86                     break;
87             }
88         }
89     }
90
91     function onEndShowStatusNetStyles($action)
92     {
93         $action->cssLink(common_path('plugins/UAP/uap.css'),
94                          null, 'screen, projection, tv');
95         return true;
96     }
97
98     //MediumRectangle ad
99     function onStartShowAside($action)
100     {
101         if (!$this->MediumRectangle) {
102             return true;
103         }
104
105         $this->showAd($action, array('id' => 'ad_medium-rectangle'), 
106                                $this->MediumRectangle);
107
108         return true;
109     }
110
111 /*
112     //Rectangle ad
113     function onEndShowSiteNotice($action)
114     {
115         if (!$this->Rectangle) {
116             return true;
117         }
118
119         $this->showAd($action, array('id' => 'ad_rectangle'), 
120                                $this->Rectangle);
121
122         return true;
123     }
124 */
125
126     //Leaderboard and Rectangle ad
127     function onStartShowHeader($action)
128     {
129         if ($this->Leaderboard) {
130             $this->showAd($action, array('id' => 'ad_leaderboard'), 
131                                    $this->Leaderboard);
132         }
133
134         if ($this->Rectangle) {
135             $this->showAd($action, array('id' => 'ad_rectangle'), 
136                                    $this->Rectangle);
137         }
138
139         return true;
140     }
141
142     //WideSkyscraper ad
143     function onEndShowAside($action)
144     {
145         if (!$this->WideSkyscraper) {
146             return true;
147         }
148
149         $this->showAd($action, array('id' => 'ad_wide-skyscraper'), 
150                                $this->WideSkyscraper);
151
152         return true;
153     }
154
155     //Output ad container
156     function showAd($action, $attr=array(), $value)
157     {
158         $classes = ($attr['class']) ? $attr['class'].' ' : '';
159
160         $action->elementStart('div', array('id' => $attr['id'],
161                                            'class' => $classes.'ad'));
162         $action->raw($value);
163         $action->elementEnd('div');
164     }
165
166     function onPluginVersion(&$versions)
167     {
168         $versions[] = array('name' => 'UAP',
169                             'version' => STATUSNET_VERSION,
170                             'author' => 'Sarven Capadisli',
171                             'homepage' => 'http://status.net/wiki/Plugin:UAP',
172                             'rawdescription' =>
173                             _m('Outputs ad placements based on Universal Ad Package'));
174         return true;
175     }
176 }