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/
81 class AdsensePlugin extends UAPPlugin
83 public $adScript = 'http://pagead2.googlesyndication.com/pagead/show_ads.js';
84 public $client = null;
90 // A little bit of chicanery so we avoid overwriting values that
91 // are passed in with the constructor
93 foreach (array('mediumRectangle', 'rectangle', 'leaderboard', 'wideSkyscraper', 'adScript', 'client') as $setting) {
94 $value = common_config('adsense', strtolower($setting));
95 if (!empty($value)) { // not found
96 $this->$setting = $value;
102 * Show a medium rectangle 'ad'
104 * @param Action $action Action being shown
109 protected function showMediumRectangle($action)
111 $this->showAdsenseCode($action, 300, 250, $this->mediumRectangle);
115 * Show a rectangle 'ad'
117 * @param Action $action Action being shown
122 protected function showRectangle($action)
124 $this->showAdsenseCode($action, 180, 150, $this->rectangle);
128 * Show a wide skyscraper ad
130 * @param Action $action Action being shown
135 protected function showWideSkyscraper($action)
137 $this->showAdsenseCode($action, 160, 600, $this->wideSkyscraper);
141 * Show a leaderboard ad
143 * @param Action $action Action being shown
148 protected function showLeaderboard($action)
150 $this->showAdsenseCode($action, 728, 90, $this->leaderboard);
154 * Output the bits of JavaScript code to show Adsense
156 * @param Action $action Action being shown
157 * @param integer $width Width of the block
158 * @param integer $height Height of the block
159 * @param string $slot Slot identifier
164 protected function showAdsenseCode($action, $width, $height, $slot)
166 $code = 'google_ad_client = "'.$this->client.'"; ';
167 $code .= 'google_ad_slot = "'.$slot.'"; ';
168 $code .= 'google_ad_width = '.$width.'; ';
169 $code .= 'google_ad_height = '.$height.'; ';
171 $action->inlineScript($code);
173 $action->script($this->adScript);
176 function onRouterInitialized($m)
178 $m->connect('admin/adsense',
179 array('action' => 'adsenseadminpanel'));
184 function onAutoload($cls)
186 $dir = dirname(__FILE__);
190 case 'AdsenseadminpanelAction':
191 require_once $dir . '/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
198 function onEndAdminPanelNav($menu) {
199 if (AdminPanelAction::canAdmin('adsense')) {
200 // TRANS: Menu item title/tooltip
201 $menu_title = _('Adsense configuration');
202 // TRANS: Menu item for site administration
203 $menu->out->menuItem(common_local_url('adsenseadminpanel'), _('Adsense'),
204 $menu_title, $action_name == 'adsenseadminpanel', 'nav_adsense_admin_panel');