3 * StatusNet, the distributed open-source microblogging tool
5 * Plugin for Google Adsense
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.
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.
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/>.
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/
30 if (!defined('STATUSNET')) {
35 * Plugin to add Google Adsense to StatusNet sites
37 * This plugin lets you add Adsense ad units to your StatusNet site.
39 * We support the 4 ad sizes for the Universal Ad Platform (UAP):
46 * They fit in different places on the default theme. Some themes
47 * might interact quite poorly with this plugin.
49 * To enable advertising, you must sign up with Google Adsense and
52 * https://www.google.com/adsense/
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.
59 * Add the plugin to config.php like so:
61 * addPlugin('Adsense', array('client' => 'Your client ID',
62 * 'rectangle' => 'slot'));
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'.
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.
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/
80 class AdsensePlugin extends UAPPlugin
82 public $adScript = 'http://pagead2.googlesyndication.com/pagead/show_ads.js';
83 public $client = null;
89 // A little bit of chicanery so we avoid overwriting values that
90 // are passed in with the constructor
91 foreach (array('mediumRectangle', 'rectangle', 'leaderboard', 'wideSkyscraper', 'adScript', 'client') as $setting) {
92 $value = common_config('adsense', strtolower($setting));
93 if (!empty($value)) { // not found
94 $this->$setting = $value;
100 * Show a medium rectangle 'ad'
102 * @param Action $action Action being shown
106 protected function showMediumRectangle($action)
108 $this->showAdsenseCode($action, 300, 250, $this->mediumRectangle);
112 * Show a rectangle 'ad'
114 * @param Action $action Action being shown
118 protected function showRectangle($action)
120 $this->showAdsenseCode($action, 180, 150, $this->rectangle);
124 * Show a wide skyscraper ad
126 * @param Action $action Action being shown
130 protected function showWideSkyscraper($action)
132 $this->showAdsenseCode($action, 160, 600, $this->wideSkyscraper);
136 * Show a leaderboard ad
138 * @param Action $action Action being shown
142 protected function showLeaderboard($action)
144 $this->showAdsenseCode($action, 728, 90, $this->leaderboard);
148 * Output the bits of JavaScript code to show Adsense
150 * @param Action $action Action being shown
151 * @param integer $width Width of the block
152 * @param integer $height Height of the block
153 * @param string $slot Slot identifier
157 protected function showAdsenseCode($action, $width, $height, $slot)
159 $code = 'google_ad_client = "'.$this->client.'"; ';
160 $code .= 'google_ad_slot = "'.$slot.'"; ';
161 $code .= 'google_ad_width = '.$width.'; ';
162 $code .= 'google_ad_height = '.$height.'; ';
164 $action->inlineScript($code);
166 $action->script($this->adScript);
169 function onRouterInitialized($m)
171 $m->connect('panel/adsense',
172 array('action' => 'adsenseadminpanel'));
177 function onEndAdminPanelNav($menu) {
178 if (AdminPanelAction::canAdmin('adsense')) {
179 // TRANS: Menu item title/tooltip
180 $menu_title = _m('AdSense configuration');
181 // TRANS: Menu item for site administration
182 $menu->out->menuItem(common_local_url('adsenseadminpanel'), _m('MENU','AdSense'),
183 $menu_title, $action_name == 'adsenseadminpanel', 'nav_adsense_admin_panel');
188 function onPluginVersion(&$versions)
190 $versions[] = array('name' => 'BlankAdPlugin',
191 'version' => GNUSOCIAL_VERSION,
192 'author' => 'Evan Prodromou',
193 'homepage' => 'http://status.net/wiki/Plugin:Adsense',
195 // TRANS: Plugin description.
196 _m('Plugin to add Google AdSense to StatusNet sites.'));