]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Adsense/AdsensePlugin.php
Merge branch 'testing' of git@gitorious.org:statusnet/mainline into testing
[quix0rs-gnu-social.git] / plugins / Adsense / AdsensePlugin.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Plugin for Google Adsense
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  Ads
23  * @package   StatusNet
24  * @author    Evan Prodromou <evan@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')) {
31     exit(1);
32 }
33
34 /**
35  * Plugin to add Google Adsense to StatusNet sites
36  *
37  * This plugin lets you add Adsense ad units to your StatusNet site.
38  *
39  * We support the 4 ad sizes for the Universal Ad Platform (UAP):
40  *
41  *     Medium Rectangle
42  *     (Small) Rectangle
43  *     Leaderboard
44  *     Wide Skyscraper
45  *
46  * They fit in different places on the default theme. Some themes
47  * might interact quite poorly with this plugin.
48  *
49  * To enable advertising, you must sign up with Google Adsense and
50  * get a client ID.
51  *
52  *     https://www.google.com/adsense/
53  *
54  * You'll also need to create an Adsense for Content unit in one
55  * of the four sizes described above. At the end of the process,
56  * note the "google_ad_client" and "google_ad_slot" values in the
57  * resultant Javascript.
58  *
59  * Add the plugin to config.php like so:
60  *
61  *     addPlugin('Adsense', array('client' => 'Your client ID',
62  *                                'rectangle' => 'slot'));
63  *
64  * Here, your client ID is the value of google_ad_client and the
65  * slot is the value of google_ad_slot. Note that if you create
66  * a different size, you'll need to provide different arguments:
67  * 'mediumRectangle', 'leaderboard', or 'wideSkyscraper'.
68  *
69  * If for some reason your ad server is different from the default,
70  * use the 'adScript' parameter to set the full path to the ad script.
71  *
72  * @category Plugin
73  * @package  StatusNet
74  * @author   Evan Prodromou <evan@status.net>
75  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
76  * @link     http://status.net/
77  *
78  * @seeAlso  UAPPlugin
79  */
80
81 class AdsensePlugin extends UAPPlugin
82 {
83     public $adScript = 'http://pagead2.googlesyndication.com/pagead/show_ads.js';
84     public $client   = null;
85
86     /**
87      * Show a medium rectangle 'ad'
88      *
89      * @param Action $action Action being shown
90      *
91      * @return void
92      */
93
94     protected function showMediumRectangle($action)
95     {
96         $this->showAdsenseCode($action, 300, 250, $this->mediumRectangle);
97     }
98
99     /**
100      * Show a rectangle 'ad'
101      *
102      * @param Action $action Action being shown
103      *
104      * @return void
105      */
106
107     protected function showRectangle($action)
108     {
109         $this->showAdsenseCode($action, 180, 150, $this->rectangle);
110     }
111
112     /**
113      * Show a wide skyscraper ad
114      *
115      * @param Action $action Action being shown
116      *
117      * @return void
118      */
119
120     protected function showWideSkyscraper($action)
121     {
122         $this->showAdsenseCode($action, 160, 600, $this->wideSkyscraper);
123     }
124
125     /**
126      * Show a leaderboard ad
127      *
128      * @param Action $action Action being shown
129      *
130      * @return void
131      */
132
133     protected function showLeaderboard($action)
134     {
135         $this->showAdsenseCode($action, 728, 90, $this->leaderboard);
136     }
137
138     /**
139      * Output the bits of JavaScript code to show Adsense
140      *
141      * @param Action  $action Action being shown
142      * @param integer $width  Width of the block
143      * @param integer $height Height of the block
144      * @param string  $slot   Slot identifier
145      *
146      * @return void
147      */
148
149     protected function showAdsenseCode($action, $width, $height, $slot)
150     {
151         $code  = 'google_ad_client = "'.$this->client.'"; ';
152         $code .= 'google_ad_slot = "'.$slot.'"; ';
153         $code .= 'google_ad_width = '.$width.'; ';
154         $code .= 'google_ad_height = '.$height.'; ';
155
156         $action->inlineScript($code);
157
158         $action->script($this->adScript);
159     }
160 }