]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/OpenX/OpenXPlugin.php
using an action for output in OpenX plugin
[quix0rs-gnu-social.git] / plugins / OpenX / OpenXPlugin.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Plugin for OpenX ad server
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 $_OpenXPlugin_Script = <<<ENDOFSCRIPT
35 var m3_u = '%s';
36 var m3_r = Math.floor(Math.random()*99999999999);
37 if (!document.MAX_used) document.MAX_used = ',';
38 document.write ("<scr"+"ipt type='text/javascript' src='"+m3_u);
39 document.write ("?zoneid=%s");
40 document.write ('&amp;cb=' + m3_r);
41 if (document.MAX_used != ',') document.write ("&amp;exclude=" + document.MAX_used);
42 document.write (document.charset ? '&amp;charset='+document.charset : (document.characterSet ? '&amp;charset='+document.characterSet : ''));
43 document.write ("&amp;loc=" + escape(window.location));
44 if (document.referrer) document.write ("&amp;referer=" + escape(document.referrer));
45 if (document.context) document.write ("&context=" + escape(document.context));
46 if (document.mmm_fo) document.write ("&amp;mmm_fo=1");
47 document.write ("'><\/scr"+"ipt>");
48 ENDOFSCRIPT;
49
50 /**
51  * Plugin for OpenX Ad Server
52  *
53  * This plugin supports the OpenX ad server, http://www.openx.org/
54  *
55  * We support the 4 ad sizes for the Universal Ad Platform (UAP):
56  *
57  *     Medium Rectangle
58  *     (Small) Rectangle
59  *     Leaderboard
60  *     Wide Skyscraper
61  *
62  * They fit in different places on the default theme. Some themes
63  * might interact quite poorly with this plugin.
64  *
65  * To enable advertising, you will need an OpenX server. You'll need
66  * to set up a "zone" for your StatusNet site that identifies a
67  * kind of ad you want to place (of the above 4 sizes).
68  *
69  * Add the plugin to config.php like so:
70  *
71  *     addPlugin('OpenX', array('adScript' => 'full path to script',
72  *                              'rectangle' => 1));
73  *
74  * Here, the 'adScript' parameter is the full path to the OpenX
75  * ad script, like 'http://example.com/www/delivery/ajs.php'. Note
76  * that we don't do any magic to swap between HTTP and HTTPS, so
77  * if you want HTTPS, say so.
78  *
79  * The 'rectangle' parameter is the zone ID for that ad space on
80  * your site. If you've configured another size, try 'mediumRectangle',
81  * 'leaderboard', or 'wideSkyscraper'.
82  *
83  * If for some reason your ad server is different from the default,
84  * use the 'adScript' parameter to set the full path to the ad script.
85  *
86  * @category Ads
87  * @package  StatusNet
88  * @author   Evan Prodromou <evan@status.net>
89  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
90  * @link     http://status.net/
91  *
92  * @seeAlso  UAPPlugin
93  */
94
95 class OpenXPlugin extends UAPPlugin
96 {
97     public $adScript = null;
98
99     /**
100      * Show a medium rectangle 'ad'
101      *
102      * @param Action $action Action being shown
103      *
104      * @return void
105      */
106
107     protected function showMediumRectangle($action)
108     {
109         $this->showAd($action, $this->mediumRectangle);
110     }
111
112     /**
113      * Show a rectangle 'ad'
114      *
115      * @param Action $action Action being shown
116      *
117      * @return void
118      */
119
120     protected function showRectangle($action)
121     {
122         $this->showAd($action, $this->rectangle);
123     }
124
125     /**
126      * Show a wide skyscraper ad
127      *
128      * @param Action $action Action being shown
129      *
130      * @return void
131      */
132
133     protected function showWideSkyscraper($action)
134     {
135         $this->showAd($action, $this->wideSkyscraper);
136     }
137
138     /**
139      * Show a leaderboard ad
140      *
141      * @param Action $action Action being shown
142      *
143      * @return void
144      */
145
146     protected function showLeaderboard($action)
147     {
148         $this->showAd($action, $this->leaderboard);
149     }
150
151     /**
152      * Show an ad using OpenX
153      *
154      * @param Action  $action Action being shown
155      * @param integer $zone   Zone to show
156      *
157      * @return void
158      */
159
160     protected function showAd($action, $zone)
161     {
162         global $_OpenXPlugin_Script;
163
164         $action->inlineScript(sprintf($_OpenXPlugin_Script, $this->adScript, $zone));
165         return true;
166     }
167 }