Ejemplo n.º 1
0
function OA_SPCGetJavaScript($affiliateid)
{
    $aConf = $GLOBALS['_MAX']['CONF'];
    $varprefix = $aConf['var']['prefix'];
    $aZones = OA_cacheGetPublisherZones($affiliateid);
    foreach ($aZones as $zoneid => $aZone) {
        $zones[$aZone['type']][] = "            '" . addslashes($aZone['name']) . "' : {$zoneid}";
    }
    $additionalParams = '';
    $magic_quotes_gpc = ini_get('magic_quotes_gpc');
    foreach ($_GET as $key => $value) {
        if ($key == 'id') {
            continue;
        }
        if ($magic_quotes_gpc) {
            $value = stripslashes($value);
        }
        $additionalParams .= htmlspecialchars('&' . urlencode($key) . '=' . urlencode($value), ENT_QUOTES);
    }
    $script = "\n    if (typeof({$varprefix}zones) != 'undefined') {\n        var {$varprefix}zoneids = '';\n        for (var zonename in {$varprefix}zones) {$varprefix}zoneids += escape(zonename+'=' + {$varprefix}zones[zonename] + \"|\");\n        {$varprefix}zoneids += '&amp;nz=1';\n    } else {\n        var {$varprefix}zoneids = escape('" . implode('|', array_keys($aZones)) . "');\n    }\n\n    if (typeof({$varprefix}source) == 'undefined') { {$varprefix}source = ''; }\n    var {$varprefix}p=location.protocol=='https:'?'" . MAX_commonConstructSecureDeliveryUrl($aConf['file']['singlepagecall'], true) . "':'" . MAX_commonConstructDeliveryUrl($aConf['file']['singlepagecall']) . "';\n    var {$varprefix}r=Math.floor(Math.random()*99999999);\n    {$varprefix}output = new Array();\n\n    var {$varprefix}spc=\"<\"+\"script type='text/javascript' \";\n    {$varprefix}spc+=\"src='\"+{$varprefix}p+\"?zones=\"+{$varprefix}zoneids;\n    {$varprefix}spc+=\"&amp;source=\"+escape({$varprefix}source)+\"&amp;r=\"+{$varprefix}r;" . (!empty($additionalParams) ? "\n    {$varprefix}spc+=\"{$additionalParams}\";" : '') . "\n    ";
    if (empty($_GET['charset'])) {
        $script .= "{$varprefix}spc+=(document.charset ? '&amp;charset='+document.charset : (document.characterSet ? '&amp;charset='+document.characterSet : ''));\n";
    }
    $script .= "\n    if (window.location) {$varprefix}spc+=\"&amp;loc=\"+escape(window.location);\n    if (document.referrer) {$varprefix}spc+=\"&amp;referer=\"+escape(document.referrer);\n    {$varprefix}spc+=\"'><\"+\"/script>\";\n    document.write({$varprefix}spc);\n\n    function {$varprefix}show(name) {\n        if (typeof({$varprefix}output[name]) == 'undefined') {\n            return;\n        } else {\n            document.write({$varprefix}output[name]);\n        }\n    }\n\n    function {$varprefix}showpop(name) {\n        zones = window.{$varprefix}zones ? window.{$varprefix}zones : false;\n        var zoneid = name;\n        if (typeof(window.{$varprefix}zones) != 'undefined') {\n            if (typeof(zones[name]) == 'undefined') {\n                return;\n            }\n            zoneid = zones[name];\n        }\n\n        {$varprefix}p=location.protocol=='https:'?'" . MAX_commonConstructSecureDeliveryUrl($aConf['file']['popup'], true) . "':'" . MAX_commonConstructDeliveryUrl($aConf['file']['popup']) . "';\n\n        var {$varprefix}pop=\"<\"+\"script type='text/javascript' \";\n        {$varprefix}pop+=\"src='\"+{$varprefix}p+\"?zoneid=\"+zoneid;\n        {$varprefix}pop+=\"&amp;source=\"+escape({$varprefix}source)+\"&amp;r=\"+{$varprefix}r;" . (!empty($additionalParams) ? "\n        {$varprefix}spc+=\"{$additionalParams}\";" : '') . "\n        if (window.location) {$varprefix}pop+=\"&amp;loc=\"+escape(window.location);\n        if (document.referrer) {$varprefix}pop+=\"&amp;referer=\"+escape(document.referrer);\n        {$varprefix}pop+=\"'><\"+\"/script>\";\n\n        document.write({$varprefix}pop);\n    }\n";
    // Add the FlashObject include to the SPC output
    $script .= MAX_javascriptToHTML(MAX_flashGetFlashObjectExternal(), $varprefix . 'fo');
    return $script;
}
Ejemplo n.º 2
0
/**
 * This is the SPC wrapper for local-mode invocation
 *
 * @param mixed $what Either a predifined array of $what = array(zoneid => array('name' => 'zonename'))
 *                    or an the publisher id (int)
 * @param string $target The target window for links
 * @param string $source The "source" value, used for "Site:Source" delivery limitations
 * @param int    $withtext 1/0 should the "Text below banner" be appended to the banner HTML
 * @param int    $block 1/0 Should a banner only be shown once on the page?
 * @param int    $blockcampaign (0/1) Should only one banner per campaign be shown on the page
 * @return array An array of the HTML to render the selected ads
 */
function view_spc($what, $target = '', $source = '', $withtext = 0, $block = 0, $blockcampaign = 0)
{
    global $context;
    if (is_numeric($what)) {
        $zones = OA_cacheGetPublisherZones($what);
        $nz = false;
    } else {
        $zones = $what;
        $nz = true;
    }
    $spc_output = array();
    $fo_required = false;
    foreach ($zones as $zone => $data) {
        if (empty($zone)) {
            continue;
        }
        // nz is set when "named zones" are being used, this allows a zone to be selected more than once
        if ($nz) {
            $varname = $zone;
            $zoneid = $data;
        } else {
            $varname = $zoneid = $zone;
        }
        // Get the banner
        $output = MAX_adSelect('zone:' . $zoneid, '', $target, $source, $withtext, $charset, $context, true, '', $GLOBALS['loc'], $GLOBALS['referer']);
        if (isset($output['contenttype']) && $output['contenttype'] == 'swf') {
            $fo_required = true;
        }
        $spc_output[$varname] = $output['html'];
        // Block this banner for next invocation
        if (!empty($block) && !empty($output['bannerid'])) {
            $output['context'][] = array('!=' => 'bannerid:' . $output['bannerid']);
        }
        // Block this campaign for next invocation
        if (!empty($blockcampaign) && !empty($output['campaignid'])) {
            $output['context'][] = array('!=' => 'campaignid:' . $output['campaignid']);
        }
        // Pass the context array back to the next call, have to iterate over elements to prevent duplication
        if (!empty($output['context'])) {
            foreach ($output['context'] as $id => $contextArray) {
                if (!in_array($contextArray, $context)) {
                    $context[] = $contextArray;
                }
            }
        }
    }
    // Make sure the FlashObject library is available if required
    if ($fo_required) {
        echo MAX_flashGetFlashObjectExternal();
    }
    return $spc_output;
}
Ejemplo n.º 3
0
/**
 * A function to handle XML-RPC advertisement SPC requests.
 *
 * @param XML_RPC_Message $params An XML_RPC_Message containing the parameters. The expected parameters
 *                              are (in order):
 *                              - An XML_RPC_Value of type "struct"  containing remote informations
 *                                which needs at least two members:
 *                                - remote_addr (string) and
 *                                - cookies     (struct);
 *                              - An XML_RPC_Value of type "string"  containing the "what" value;
 *                              - An XML_RPC_Value of type "string"  containing the "target" value;
 *                              - An XML_RPC_Value of type "string"  containing the "source" value;
 *                              - An XML_RPC_Value of type "boolean" containing the "withtext" value;
 *                              - An XML_RPC_Value of type "boolean" containing the "block" value;
 *                              - An XML_RPC_Value of type "boolean" containing the "blockcampaign" value;
 * @return XML_RPC_Response The response. The XML_RPC_Value of the response can be one of
 *                          a number of different values:
 *                          - Error Code 21: wrong number of parameters.
 *                          - Error Code 22: remote_addr element missing from the remote info struct.
 *                          - Error Code 23: cookies element missing from the remote info struct.
 *                          - An XML_RPC_Value of type "struct" with the HTML details required
 *                            for displaying the advertisement stored as in XML_RPC_Value of
 *                            type "string" in the "html" index, and other elements returned by the
 *                            MAX_asSelect call. A special "cookies" element is either:
 *                            - An empty XML_RPC_Value if there are no cookies to be set, or
 *                            - An XML_RPC_Value of type "array", containing a number of XML_RPC_Values
 *                              of tpye "array", each with 3 items:
 *                              - An XML_RPC_Value of type "string" with the cookie name;
 *                              - An XML_RPC_Value of type "string" with the cookie value; and
 *                              - An XML_RPC_Value of type "string" with the cookie expiration time.
 */
function OA_Delivery_XmlRpc_SPC($params)
{
    global $XML_RPC_erruser;
    global $XML_RPC_String, $XML_RPC_Struct, $XML_RPC_Array;
    // Check the parameters exist
    $numParams = $params->getNumParams();
    if ($numParams != 7) {
        // Return an error
        $errorCode = $XML_RPC_erruser + 21;
        $errorMsg = 'Incorrect number of parameters';
        return new XML_RPC_Response(0, $errorCode, $errorMsg);
    }
    // Set the XML values into their correct variables to make life easier
    $vars = array(1 => 'what', 2 => 'target', 3 => 'source', 4 => 'withtext', 5 => 'block', 6 => 'blockcampaign');
    // Parse parameters
    for ($i = 0; $i < $numParams; $i++) {
        $p = $params->getParam($i);
        if ($i) {
            // Put the decoded value the view arg array
            ${$vars}[$i] = XML_RPC_decode($p);
        } else {
            // First parameter: environment information supplied be XML-RPC client
            $p = XML_RPC_decode($p);
            if (!isset($p['remote_addr'])) {
                // Return an error
                $errorCode = $XML_RPC_erruser + 22;
                $errorMsg = "Missing 'remote_addr' member";
                return new XML_RPC_Response(0, $errorCode, $errorMsg);
            }
            if (!isset($p['cookies']) || !is_array($p['cookies'])) {
                // Return an error
                $errorCode = $XML_RPC_erruser + 23;
                $errorMsg = "Missing 'cookies' member";
                return new XML_RPC_Response(0, $errorCode, $errorMsg);
            }
            $aServerVars = array('remote_addr' => 'REMOTE_ADDR', 'remote_host' => 'REMOTE_HOST', 'request_uri' => 'REQUEST_URI', 'https' => 'HTTPS', 'server_name' => 'SERVER_NAME', 'http_host' => 'HTTP_HOST', 'accept_language' => 'HTTP_ACCEPT_LANGUAGE', 'referer' => 'HTTP_REFERER', 'user_agent' => 'HTTP_USER_AGENT', 'via' => 'HTTP_VIA', 'forwarded' => 'HTTP_FORWARDED', 'forwarded_for' => 'HTTP_FORWARDED_FOR', 'x_forwarded' => 'HTTP_X_FORWARDED', 'x_forwarded_for' => 'HTTP_X_FORWARDED_FOR', 'client_ip' => 'HTTP_CLIENT_IP');
            // Extract environment vars to $_SERVER
            foreach ($aServerVars as $xmlName => $varName) {
                if (isset($p[$xmlName])) {
                    $_SERVER[$varName] = $p[$xmlName];
                }
            }
            // Extract cookie vars to $_COOKIE
            foreach ($p['cookies'] as $key => $value) {
                $_COOKIE[$key] = MAX_commonAddslashesRecursive($value);
            }
            MAX_cookieUnpackCapping();
        }
    }
    // Add defaults for not-applicable values
    $richmedia = true;
    $ct0 = '';
    $context = array();
    // Make loc and referer global to ensure that the delivery limitations work correctly
    global $loc, $referer;
    $loc = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http') . '://' . OX_getHostName() . $_SERVER['REQUEST_URI'];
    // Add $referer parameter
    $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
    // If the what parameter is an int, it is the affiliateid, otherwise it's a serialized array of name=zone pairs
    // This convention is inline with the parameters passed into local-mode SPC
    if (is_numeric($what)) {
        $zones = OA_cacheGetPublisherZones($what);
        $nz = false;
    } else {
        $zones = unserialize($what);
        $nz = true;
    }
    $spc_output = array();
    foreach ($zones as $zone => $data) {
        if (empty($zone)) {
            continue;
        }
        // nz is set when "named zones" are being used, this allows a zone to be selected more than once
        if ($nz) {
            $varname = $zone;
            $zoneid = $data;
        } else {
            $varname = $zoneid = $zone;
        }
        // Get the banner
        $output = MAX_adSelect('zone:' . $zoneid, '', $target, $source, $withtext, '', $context, $richmedia, $ct0, $GLOBALS['loc'], $GLOBALS['referer']);
        $spc_output[$varname] = $output;
        // Block this banner for next invocation
        if (!empty($block) && !empty($output['bannerid'])) {
            $output['context'][] = array('!=' => 'bannerid:' . $output['bannerid']);
        }
        // Block this campaign for next invocation
        if (!empty($blockcampaign) && !empty($output['campaignid'])) {
            $output['context'][] = array('!=' => 'campaignid:' . $output['campaignid']);
        }
        // Pass the context array back to the next call, have to iterate over elements to prevent duplication
        if (!empty($output['context'])) {
            foreach ($output['context'] as $id => $contextArray) {
                if (!in_array($contextArray, $context)) {
                    $context[] = $contextArray;
                }
            }
        }
    }
    return new XML_RPC_Response(XML_RPC_encode($spc_output));
    // Now we have all the parameters we need to select the ad
    // Call MAX_adSelect with supplied parameters
    $output = call_user_func_array('MAX_adSelect', $view_params);
    // Prepare output as PHP array
    if (!is_array($output)) {
        $output = array();
    } elseif (isset($output['contenttype']) && $output['contenttype'] == 'swf') {
        $output['html'] = MAX_flashGetFlashObjectExternal() . $output['html'];
    }
    MAX_cookieFlush();
    // Add cookie information
    $output['cookies'] = $GLOBALS['_OA']['COOKIE']['XMLRPC_CACHE'];
    // Return response
    return new XML_RPC_Response(XML_RPC_encode($output));
}
Ejemplo n.º 4
0
function view_spc($what, $target = '', $source = '', $withtext = 0, $block = 0, $blockcampaign = 0)
{
    global $context;
    if (is_numeric($what)) {
        $zones = OA_cacheGetPublisherZones($what);
        $nz = false;
    } else {
        $zones = $what;
        $nz = true;
    }
    $spc_output = array();
    $fo_required = false;
    foreach ($zones as $zone => $data) {
        if (empty($zone)) {
            continue;
        }
        if ($nz) {
            $varname = $zone;
            $zoneid = $data;
        } else {
            $varname = $zoneid = $zone;
        }
        $output = MAX_adSelect('zone:' . $zoneid, '', $target, $source, $withtext, $charset, $context, true, '', $GLOBALS['loc'], $GLOBALS['referer']);
        if (isset($output['contenttype']) && $output['contenttype'] == 'swf') {
            $fo_required = true;
        }
        $spc_output[$varname] = $output['html'];
        if (!empty($block) && !empty($output['bannerid'])) {
            $output['context'][] = array('!=' => 'bannerid:' . $output['bannerid']);
        }
        if (!empty($blockcampaign) && !empty($output['campaignid'])) {
            $output['context'][] = array('!=' => 'campaignid:' . $output['campaignid']);
        }
        if (!empty($output['context'])) {
            foreach ($output['context'] as $id => $contextArray) {
                if (!in_array($contextArray, $context)) {
                    $context[] = $contextArray;
                }
            }
        }
    }
    if ($fo_required) {
        echo MAX_flashGetFlashObjectExternal();
    }
    return $spc_output;
}
 /**
  * Method tests invalidateWebsiteCache method
  */
 function test_invalidateWebsiteCache()
 {
     $cachedData = OA_cacheGetPublisherZones($this->_aIds['zones'][0]);
     // Delete zone
     $doZones = OA_Dal::factoryDO('zones');
     $doZones->zoneid = $this->_aIds['zones'][0];
     $doZones->delete();
     // Expect no changes in cache
     $this->assertEqual(OA_cacheGetPublisherZones($this->_aIds['zones'][0]), $cachedData);
     $this->oDeliveryCacheManager->invalidateWebsiteCache($this->_aIds['zones'][0]);
     // Now expect changes in cache
     $this->assertNotEqual(OA_cacheGetPublisherZones($this->_aIds['zones'][0]), $cachedData);
 }
Ejemplo n.º 6
0
function OA_Delivery_XmlRpc_SPC($params)
{
    global $XML_RPC_erruser;
    global $XML_RPC_String, $XML_RPC_Struct, $XML_RPC_Array;
    $numParams = $params->getNumParams();
    if ($numParams != 7) {
        $errorCode = $XML_RPC_erruser + 21;
        $errorMsg = 'Incorrect number of parameters';
        return new XML_RPC_Response(0, $errorCode, $errorMsg);
    }
    $vars = array(1 => 'what', 2 => 'target', 3 => 'source', 4 => 'withtext', 5 => 'block', 6 => 'blockcampaign');
    for ($i = 0; $i < $numParams; $i++) {
        $p = $params->getParam($i);
        if ($i) {
            ${$vars}[$i] = XML_RPC_decode($p);
        } else {
            $p = XML_RPC_decode($p);
            if (!isset($p['remote_addr'])) {
                $errorCode = $XML_RPC_erruser + 22;
                $errorMsg = "Missing 'remote_addr' member";
                return new XML_RPC_Response(0, $errorCode, $errorMsg);
            }
            if (!isset($p['cookies']) || !is_array($p['cookies'])) {
                $errorCode = $XML_RPC_erruser + 23;
                $errorMsg = "Missing 'cookies' member";
                return new XML_RPC_Response(0, $errorCode, $errorMsg);
            }
            $aServerVars = array('remote_addr' => 'REMOTE_ADDR', 'remote_host' => 'REMOTE_HOST', 'request_uri' => 'REQUEST_URI', 'https' => 'HTTPS', 'server_name' => 'SERVER_NAME', 'http_host' => 'HTTP_HOST', 'accept_language' => 'HTTP_ACCEPT_LANGUAGE', 'referer' => 'HTTP_REFERER', 'user_agent' => 'HTTP_USER_AGENT', 'via' => 'HTTP_VIA', 'forwarded' => 'HTTP_FORWARDED', 'forwarded_for' => 'HTTP_FORWARDED_FOR', 'x_forwarded' => 'HTTP_X_FORWARDED', 'x_forwarded_for' => 'HTTP_X_FORWARDED_FOR', 'client_ip' => 'HTTP_CLIENT_IP');
            foreach ($aServerVars as $xmlName => $varName) {
                if (isset($p[$xmlName])) {
                    $_SERVER[$varName] = $p[$xmlName];
                }
            }
            foreach ($p['cookies'] as $key => $value) {
                $_COOKIE[$key] = MAX_commonAddslashesRecursive($value);
            }
            MAX_remotehostSetInfo(true);
            OX_Delivery_Common_hook('postInit');
            MAX_cookieUnpackCapping();
        }
    }
    $richmedia = true;
    $ct0 = '';
    $context = array();
    global $loc, $referer;
    $loc = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http') . '://' . OX_getHostName() . $_SERVER['REQUEST_URI'];
    $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
    if (is_numeric($what)) {
        $zones = OA_cacheGetPublisherZones($what);
        $nz = false;
    } else {
        $zones = unserialize($what);
        $nz = true;
    }
    $spc_output = array();
    foreach ($zones as $zone => $data) {
        if (empty($zone)) {
            continue;
        }
        if ($nz) {
            $varname = $zone;
            $zoneid = $data;
        } else {
            $varname = $zoneid = $zone;
        }
        unset($GLOBALS['_MAX']['deliveryData']);
        $output = MAX_adSelect('zone:' . $zoneid, '', $target, $source, $withtext, '', $context, $richmedia, $ct0, $GLOBALS['loc'], $GLOBALS['referer']);
        $spc_output[$varname] = $output;
        if (!empty($block) && !empty($output['bannerid'])) {
            $output['context'][] = array('!=' => 'bannerid:' . $output['bannerid']);
        }
        if (!empty($blockcampaign) && !empty($output['campaignid'])) {
            $output['context'][] = array('!=' => 'campaignid:' . $output['campaignid']);
        }
        if (!empty($output['context'])) {
            foreach ($output['context'] as $id => $contextArray) {
                if (!in_array($contextArray, $context)) {
                    $context[] = $contextArray;
                }
            }
        }
    }
    return new XML_RPC_Response(XML_RPC_encode($spc_output));
    $output = call_user_func_array('MAX_adSelect', $view_params);
    if (!is_array($output)) {
        $output = array();
    } elseif (isset($output['contenttype']) && $output['contenttype'] == 'swf') {
        $output['html'] = MAX_flashGetFlashObjectExternal() . $output['html'];
    }
    MAX_cookieFlush();
    $output['cookies'] = $GLOBALS['_OA']['COOKIE']['XMLRPC_CACHE'];
    return new XML_RPC_Response(XML_RPC_encode($output));
}
 /**
  * Creates all possible delivert cache files
  *
  * @param array $aIds array of DB Ids returned by _createTestData
  * @see _createTestData
  */
 function _createTestCacheFiles($aIds)
 {
     // Create cache files not related to DB Objects
     MAX_cacheGetAccountTZs();
     MAX_cacheCheckIfMaintenanceShouldRun();
     MAX_cacheGetGoogleJavaScript();
     // Create cache files for banners and images
     foreach ($aIds['banners'] as $bannerId) {
         MAX_cacheGetAd($bannerId);
     }
     foreach ($aIds['images'] as $filename) {
         MAX_cacheGetCreative($filename);
     }
     // Create cache files for zones
     foreach ($aIds['zones'] as $zoneId) {
         MAX_cacheGetZoneLinkedAds($zoneId);
         MAX_cacheGetZoneInfo($zoneId);
     }
     // Create cache files for websites
     foreach ($aIds['affiliates'] as $affiliateid) {
         OA_cacheGetPublisherZones($affiliateid);
     }
     // Create cache files for trackers
     foreach ($aIds['trackers'] as $trackerid) {
         MAX_cacheGetTracker($trackerid);
         MAX_cacheGetTrackerVariables($trackerid);
     }
     // Create cache files for channels
     foreach ($aIds['channel'] as $channelid) {
         MAX_cacheGetChannelLimitations($channelid);
     }
     // cache files for direct-selection are not created
     // due to problems with invalidating MAX_cacheGetLinkedAds
 }
 /**
  * Method tests invalidatePublisherZonesCache method
  */
 function test_invalidatePublisherZonesCache()
 {
     $aIds = $this->_createTestData();
     $this->_createTestCacheFiles($aIds);
     $cachedData = OA_cacheGetPublisherZones($aIds['affiliates'][0]);
     // Change zone
     $doZone = OA_Dal::factoryDO('zones');
     $doZone->get($aIds['zones'][0]);
     $doZone->zonename = 'new name';
     $doZone->update();
     // Expect no changes in cache
     $this->assertEqual(OA_cacheGetPublisherZones($aIds['affiliates'][0]), $cachedData);
     $this->oDeliveryCacheCommon->invalidatePublisherZonesCache($aIds['zones'][0]);
     // Now expect changes in cache
     $cachedData2 = OA_cacheGetPublisherZones($aIds['affiliates'][0]);
     $this->assertNotEqual($cachedData2, $cachedData);
     // Delete zone
     $doZones = OA_Dal::factoryDO('zones');
     $doZones->zoneid = $aIds['zones'][0];
     $doZones->delete();
     // Expect no changes in cache
     $this->assertEqual(OA_cacheGetPublisherZones($aIds['affiliates'][0]), $cachedData2);
     $this->oDeliveryCacheCommon->invalidatePublisherZonesCache($aIds['affiliates'][0]);
     // Now expect changes in cache
     $cachedData3 = OA_cacheGetPublisherZones($aIds['affiliates'][0]);
     $this->assertNotEqual($cachedData3, $cachedData2);
 }