PageRenderTime 37ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/www/delivery_dev/spcjs.php

https://bitbucket.org/valmy/openx
PHP | 142 lines | 89 code | 21 blank | 32 comment | 21 complexity | df337dae185734d1ace159c3e4988272 MD5 | raw file
  1. <?php
  2. /*
  3. +---------------------------------------------------------------------------+
  4. | OpenX v2.8 |
  5. | ========== |
  6. | |
  7. | Copyright (c) 2003-2009 OpenX Limited |
  8. | For contact details, see: http://www.openx.org/ |
  9. | |
  10. | This program is free software; you can redistribute it and/or modify |
  11. | it under the terms of the GNU General Public License as published by |
  12. | the Free Software Foundation; either version 2 of the License, or |
  13. | (at your option) any later version. |
  14. | |
  15. | This program is distributed in the hope that it will be useful, |
  16. | but WITHOUT ANY WARRANTY; without even the implied warranty of |
  17. | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
  18. | GNU General Public License for more details. |
  19. | |
  20. | You should have received a copy of the GNU General Public License |
  21. | along with this program; if not, write to the Free Software |
  22. | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
  23. +---------------------------------------------------------------------------+
  24. $Id$
  25. */
  26. // Require the initialisation file
  27. require_once '../../init-delivery.php';
  28. // Required files
  29. require_once MAX_PATH . '/lib/max/Delivery/cache.php';
  30. require_once MAX_PATH . '/lib/max/Delivery/javascript.php';
  31. require_once MAX_PATH . '/lib/max/Delivery/flash.php';
  32. // Get the affiliateid from the querystring if present
  33. MAX_commonRegisterGlobalsArray(array('id'));
  34. // Get JS
  35. $output = OA_SPCGetJavaScript($id);
  36. //OX_Delivery_logMessage('output: ' . $output, 7);
  37. // Output JS
  38. MAX_commonSendContentTypeHeader("application/x-javascript");
  39. header("Content-Size: ".strlen($output));
  40. header("Expires: ".gmdate('r', time() + 86400));
  41. // Flush cookies
  42. MAX_cookieFlush();
  43. echo $output;
  44. function OA_SPCGetJavaScript($affiliateid)
  45. {
  46. $aConf = $GLOBALS['_MAX']['CONF'];
  47. $varprefix = $aConf['var']['prefix'];
  48. $aZones = OA_cacheGetPublisherZones($affiliateid);
  49. foreach ($aZones as $zoneid => $aZone) {
  50. $zones[$aZone['type']][] = " '" . addslashes($aZone['name']) . "' : {$zoneid}";
  51. }
  52. $additionalParams = '';
  53. $magic_quotes_gpc = ini_get('magic_quotes_gpc');
  54. foreach ($_GET as $key => $value) {
  55. if ($key == 'id') { continue; }
  56. if ($magic_quotes_gpc) { $value = stripslashes($value); }
  57. $additionalParams .= htmlspecialchars('&'.urlencode($key).'='.urlencode($value), ENT_QUOTES);
  58. }
  59. $script = "
  60. if (typeof({$varprefix}zones) != 'undefined') {
  61. var {$varprefix}zoneids = '';
  62. for (var zonename in {$varprefix}zones) {$varprefix}zoneids += escape(zonename+'=' + {$varprefix}zones[zonename] + \"|\");
  63. {$varprefix}zoneids += '&amp;nz=1';
  64. } else {
  65. var {$varprefix}zoneids = escape('" . implode('|', array_keys($aZones)) . "');
  66. }
  67. if (typeof({$varprefix}source) == 'undefined') { {$varprefix}source = ''; }
  68. var {$varprefix}p=location.protocol=='https:'?'".
  69. MAX_commonConstructSecureDeliveryUrl($aConf['file']['singlepagecall'], true).
  70. "':'".
  71. MAX_commonConstructDeliveryUrl($aConf['file']['singlepagecall'])."';
  72. var {$varprefix}r=Math.floor(Math.random()*99999999);
  73. {$varprefix}output = new Array();
  74. var {$varprefix}spc=\"<\"+\"script type='text/javascript' \";
  75. {$varprefix}spc+=\"src='\"+{$varprefix}p+\"?zones=\"+{$varprefix}zoneids;
  76. {$varprefix}spc+=\"&amp;source=\"+escape({$varprefix}source)+\"&amp;r=\"+{$varprefix}r;" .
  77. ((!empty($additionalParams)) ? "\n {$varprefix}spc+=\"{$additionalParams}\";" : '') . "
  78. ";
  79. if (empty($_GET['charset'])) {
  80. $script .= "{$varprefix}spc+=(document.charset ? '&amp;charset='+document.charset : (document.characterSet ? '&amp;charset='+document.characterSet : ''));\n";
  81. }
  82. $script .= "
  83. if (window.location) {$varprefix}spc+=\"&amp;loc=\"+escape(window.location);
  84. if (document.referrer) {$varprefix}spc+=\"&amp;referer=\"+escape(document.referrer);
  85. {$varprefix}spc+=\"'><\"+\"/script>\";
  86. document.write({$varprefix}spc);
  87. function {$varprefix}show(name) {
  88. if (typeof({$varprefix}output[name]) == 'undefined') {
  89. return;
  90. } else {
  91. document.write({$varprefix}output[name]);
  92. }
  93. }
  94. function {$varprefix}showpop(name) {
  95. zones = window.{$varprefix}zones ? window.{$varprefix}zones : false;
  96. var zoneid = name;
  97. if (typeof(window.{$varprefix}zones) != 'undefined') {
  98. if (typeof(zones[name]) == 'undefined') {
  99. return;
  100. }
  101. zoneid = zones[name];
  102. }
  103. {$varprefix}p=location.protocol=='https:'?'".
  104. MAX_commonConstructSecureDeliveryUrl($aConf['file']['popup'], true).
  105. "':'".
  106. MAX_commonConstructDeliveryUrl($aConf['file']['popup'])."';
  107. var {$varprefix}pop=\"<\"+\"script type='text/javascript' \";
  108. {$varprefix}pop+=\"src='\"+{$varprefix}p+\"?zoneid=\"+zoneid;
  109. {$varprefix}pop+=\"&amp;source=\"+escape({$varprefix}source)+\"&amp;r=\"+{$varprefix}r;" .
  110. ((!empty($additionalParams)) ? "\n {$varprefix}spc+=\"{$additionalParams}\";" : '') . "
  111. if (window.location) {$varprefix}pop+=\"&amp;loc=\"+escape(window.location);
  112. if (document.referrer) {$varprefix}pop+=\"&amp;referer=\"+escape(document.referrer);
  113. {$varprefix}pop+=\"'><\"+\"/script>\";
  114. document.write({$varprefix}pop);
  115. }
  116. ";
  117. // Add the FlashObject include to the SPC output
  118. $script .= MAX_javascriptToHTML(MAX_flashGetFlashObjectExternal(), $varprefix . 'fo');
  119. return $script;
  120. }
  121. ?>