]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/OpenX/OpenXPlugin.php
Merge branch 'nightly' into 'nightly'
[quix0rs-gnu-social.git] / plugins / OpenX / OpenXPlugin.php
index a0d02ec1170a96e4a21c4958f466f8e151ecdf73..8d80197be35aeed6e7933a07ad5e244d2e232264 100644 (file)
@@ -31,22 +31,6 @@ if (!defined('STATUSNET')) {
     exit(1);
 }
 
-$_OpenXPlugin_Script = <<<ENDOFSCRIPT
-var m3_u = '%s';
-var m3_r = Math.floor(Math.random()*99999999999);
-if (!document.MAX_used) document.MAX_used = ',';
-document.write ("<scr"+"ipt type='text/javascript' src='"+m3_u);
-document.write ("?zoneid=%s");
-document.write ('&amp;cb=' + m3_r);
-if (document.MAX_used != ',') document.write ("&amp;exclude=" + document.MAX_used);
-document.write (document.charset ? '&amp;charset='+document.charset : (document.characterSet ? '&amp;charset='+document.characterSet : ''));
-document.write ("&amp;loc=" + escape(window.location));
-if (document.referrer) document.write ("&amp;referer=" + escape(document.referrer));
-if (document.context) document.write ("&context=" + escape(document.context));
-if (document.mmm_fo) document.write ("&amp;mmm_fo=1");
-document.write ("'><\/scr"+"ipt>");
-ENDOFSCRIPT;
-
 /**
  * Plugin for OpenX Ad Server
  *
@@ -91,11 +75,26 @@ ENDOFSCRIPT;
  *
  * @seeAlso  UAPPlugin
  */
-
 class OpenXPlugin extends UAPPlugin
 {
     public $adScript = null;
 
+    function initialize()
+    {
+        parent::initialize();
+
+        // A little bit of chicanery so we avoid overwriting values that
+        // are passed in with the constructor
+        foreach (array('mediumRectangle', 'rectangle', 'leaderboard', 'wideSkyscraper', 'adScript') as $setting) {
+            $value = common_config('openx', $setting);
+            if (!empty($value)) { // not found
+                $this->$setting = $value;
+            }
+        }
+
+        return true;
+    }
+
     /**
      * Show a medium rectangle 'ad'
      *
@@ -103,7 +102,6 @@ class OpenXPlugin extends UAPPlugin
      *
      * @return void
      */
-
     protected function showMediumRectangle($action)
     {
         $this->showAd($action, $this->mediumRectangle);
@@ -116,7 +114,6 @@ class OpenXPlugin extends UAPPlugin
      *
      * @return void
      */
-
     protected function showRectangle($action)
     {
         $this->showAd($action, $this->rectangle);
@@ -129,7 +126,6 @@ class OpenXPlugin extends UAPPlugin
      *
      * @return void
      */
-
     protected function showWideSkyscraper($action)
     {
         $this->showAd($action, $this->wideSkyscraper);
@@ -142,7 +138,6 @@ class OpenXPlugin extends UAPPlugin
      *
      * @return void
      */
-
     protected function showLeaderboard($action)
     {
         $this->showAd($action, $this->leaderboard);
@@ -151,16 +146,68 @@ class OpenXPlugin extends UAPPlugin
     /**
      * Show an ad using OpenX
      *
-     * @param integer $zone Zone to show
+     * @param Action  $action Action being shown
+     * @param integer $zone   Zone to show
      *
      * @return void
      */
+    protected function showAd($action, $zone)
+    {
+$scr = <<<ENDOFSCRIPT
+var m3_u = '%s';
+var m3_r = Math.floor(Math.random()*99999999999);
+if (!document.MAX_used) document.MAX_used = ',';
+document.write ("<scr"+"ipt type='text/javascript' src='"+m3_u);
+document.write ("?zoneid=%d");
+document.write ('&amp;cb=' + m3_r);
+if (document.MAX_used != ',') document.write ("&amp;exclude=" + document.MAX_used);
+document.write (document.charset ? '&amp;charset='+document.charset : (document.characterSet ? '&amp;charset='+document.characterSet : ''));
+document.write ("&amp;loc=" + escape(window.location));
+if (document.referrer) document.write ("&amp;referer=" + escape(document.referrer));
+if (document.context) document.write ("&context=" + escape(document.context));
+if (document.mmm_fo) document.write ("&amp;mmm_fo=1");
+document.write ("'><\/scr"+"ipt>");
+ENDOFSCRIPT;
 
-    protected function showAd($zone)
+        $action->inlineScript(sprintf($scr, $this->adScript, $zone));
+        return true;
+    }
+
+    function onRouterInitialized($m)
     {
-        global $_OpenXPlugin_Script;
+        $m->connect('panel/openx',
+                    array('action' => 'openxadminpanel'));
+
+        return true;
+    }
 
-        $this->inlineScript(sprintf($_OpenXPlugin_Script, $this->adScript, $zone));
+    function onEndAdminPanelNav($menu) {
+        if (AdminPanelAction::canAdmin('openx')) {
+            // TRANS: Menu item title.
+            $menu_title = _m('OpenX configuration.');
+            // TRANS: Menu item for site administration
+            $menu->out->menuItem(common_local_url('openxadminpanel'), _m('OpenX'),
+                                 $menu_title, $action_name == 'openxadminpanel', 'nav_openx_admin_panel');
+        }
         return true;
     }
-}
\ No newline at end of file
+
+    /**
+     * Add our version information to output
+     *
+     * @param array &$versions Array of version-data arrays
+     *
+     * @return boolean hook value
+     */
+    function onPluginVersion(array &$versions)
+    {
+        $versions[] = array('name' => 'OpenX',
+                            'version' => GNUSOCIAL_VERSION,
+                            'author' => 'Evan Prodromou',
+                            'homepage' => 'http://status.net/wiki/Plugin:OpenX',
+                            'rawdescription' =>
+                            // TRANS: Plugin description.
+                            _m('Plugin for <a href="http://www.openx.org/">OpenX Ad Server</a>.'));
+        return true;
+    }
+}