3 * StatusNet, the distributed open-source microblogging tool
5 * Plugin for OpenX ad server
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 for OpenX Ad Server
37 * This plugin supports the OpenX ad server, http://www.openx.org/
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 will need an OpenX server. You'll need
50 * to set up a "zone" for your StatusNet site that identifies a
51 * kind of ad you want to place (of the above 4 sizes).
53 * Add the plugin to config.php like so:
55 * addPlugin('OpenX', array('adScript' => 'full path to script',
58 * Here, the 'adScript' parameter is the full path to the OpenX
59 * ad script, like 'http://example.com/www/delivery/ajs.php'. Note
60 * that we don't do any magic to swap between HTTP and HTTPS, so
61 * if you want HTTPS, say so.
63 * The 'rectangle' parameter is the zone ID for that ad space on
64 * your site. If you've configured another size, try 'mediumRectangle',
65 * 'leaderboard', or 'wideSkyscraper'.
67 * If for some reason your ad server is different from the default,
68 * use the 'adScript' parameter to set the full path to the ad script.
72 * @author Evan Prodromou <evan@status.net>
73 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
74 * @link http://status.net/
78 class OpenXPlugin extends UAPPlugin
80 public $adScript = null;
86 // A little bit of chicanery so we avoid overwriting values that
87 // are passed in with the constructor
88 foreach (array('mediumRectangle', 'rectangle', 'leaderboard', 'wideSkyscraper', 'adScript') as $setting) {
89 $value = common_config('openx', $setting);
90 if (!empty($value)) { // not found
91 $this->$setting = $value;
99 * Show a medium rectangle 'ad'
101 * @param Action $action Action being shown
105 protected function showMediumRectangle($action)
107 $this->showAd($action, $this->mediumRectangle);
111 * Show a rectangle 'ad'
113 * @param Action $action Action being shown
117 protected function showRectangle($action)
119 $this->showAd($action, $this->rectangle);
123 * Show a wide skyscraper ad
125 * @param Action $action Action being shown
129 protected function showWideSkyscraper($action)
131 $this->showAd($action, $this->wideSkyscraper);
135 * Show a leaderboard ad
137 * @param Action $action Action being shown
141 protected function showLeaderboard($action)
143 $this->showAd($action, $this->leaderboard);
147 * Show an ad using OpenX
149 * @param Action $action Action being shown
150 * @param integer $zone Zone to show
154 protected function showAd($action, $zone)
156 $scr = <<<ENDOFSCRIPT
158 var m3_r = Math.floor(Math.random()*99999999999);
159 if (!document.MAX_used) document.MAX_used = ',';
160 document.write ("<scr"+"ipt type='text/javascript' src='"+m3_u);
161 document.write ("?zoneid=%d");
162 document.write ('&cb=' + m3_r);
163 if (document.MAX_used != ',') document.write ("&exclude=" + document.MAX_used);
164 document.write (document.charset ? '&charset='+document.charset : (document.characterSet ? '&charset='+document.characterSet : ''));
165 document.write ("&loc=" + escape(window.location));
166 if (document.referrer) document.write ("&referer=" + escape(document.referrer));
167 if (document.context) document.write ("&context=" + escape(document.context));
168 if (document.mmm_fo) document.write ("&mmm_fo=1");
169 document.write ("'><\/scr"+"ipt>");
172 $action->inlineScript(sprintf($scr, $this->adScript, $zone));
176 function onRouterInitialized($m)
178 $m->connect('admin/openx',
179 array('action' => 'openxadminpanel'));
184 function onAutoload($cls)
186 $dir = dirname(__FILE__);
190 case 'OpenxadminpanelAction':
191 require_once $dir . '/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
198 function onEndAdminPanelNav($menu) {
199 if (AdminPanelAction::canAdmin('openx')) {
200 // TRANS: Menu item title/tooltip
201 $menu_title = _m('OpenX configuration');
202 // TRANS: Menu item for site administration
203 $menu->out->menuItem(common_local_url('openxadminpanel'), _m('OpenX'),
204 $menu_title, $action_name == 'openxadminpanel', 'nav_openx_admin_panel');
210 * Add our version information to output
212 * @param array &$versions Array of version-data arrays
214 * @return boolean hook value
216 function onPluginVersion(&$versions)
218 $versions[] = array('name' => 'OpenX',
219 'version' => STATUSNET_VERSION,
220 'author' => 'Evan Prodromou',
221 'homepage' => 'http://status.net/wiki/Plugin:OpenX',
223 // TRANS: Plugin description.
224 _m('Plugin for <a href="http://www.openx.org/">OpenX Ad Server</a>.'));