/**
  * @todo functions below test for individual element structures e.g. logging beacon
  *  this function should test for total structure and presence of individual elements
  *  divA is Flash-specific object container
  *  script is Flash object code
  *  divB is logging beacon
  *
  * render an ad of type Flash
  *
  */
 function test_adRenderFlash()
 {
     $this->sendMessage('test_adRenderFlash');
     require_once MAX_PATH . '/lib/max/Delivery/common.php';
     // note: following code to extract test data from db
     //        require_once MAX_PATH . '/lib/OA/Dal/Delivery/'.$GLOBALS['_MAX']['CONF']['database']['type'].'.php';
     //        OA_Dal_Delivery_connect();
     //        $aBanner = (array)OA_Dal_Delivery_getAd(2);
     //        $prn    = print_r($aBanner, TRUE);
     require MAX_PATH . '/lib/max/Delivery/tests/data/test_adRenderFlash.php';
     $return = _adRenderFlash($aBanner, $zoneId, $source, $ct0, $withText, $logClick, $logView, $useAlt, $loc, $referer);
     $flags = null;
     $offset = null;
     // is prepended stuff returned?
     if (array_key_exists('prepend', $aBanner) && !empty($aBanner['prepend'])) {
         $i = preg_match('/' . $aPattern['pre'] . '/', $return, $aMatch);
         $this->assertTrue($i, 'prepend');
     }
     // is appended stuff returned?
     if (array_key_exists('append', $aBanner) && !empty($aBanner['append'])) {
         $i = preg_match('/' . $aPattern['app'] . '/', $return, $aMatch);
         $this->assertTrue($i, 'append');
     }
     // break known structure into array of individual elements
     $i = preg_match_all('/' . $aPattern['stru'] . '/U', $return, $aMatch);
     $this->assertTrue($i, 'structure');
     // Test a converted SWF banner
     $aBanner['parameters'] = serialize(array('swf' => array('1' => array('link' => 'http://www.example.com', 'tar' => '_blank'))));
     $return = _adRenderFlash($aBanner, $zoneId, $source, $ct0, $withText, $logClick, $logView, $useAlt, $loc, $referer);
     $flags = null;
     $offset = null;
     // is prepended stuff returned?
     if (array_key_exists('prepend', $aBanner) && !empty($aBanner['prepend'])) {
         $i = preg_match('/' . $aPattern['pre'] . '/', $return, $aMatch);
         $this->assertTrue($i, 'prepend');
     }
     // is appended stuff returned?
     if (array_key_exists('append', $aBanner) && !empty($aBanner['append'])) {
         $i = preg_match('/' . $aPattern['app'] . '/', $return, $aMatch);
         $this->assertTrue($i, 'append');
     }
     // break known structure into array of individual elements
     $i = preg_match_all('/' . $aPattern['stru'] . '/U', $return, $aMatch);
     $this->assertTrue($i, 'structure');
     // Check for converded link (now a FlashVar)
     $this->assertTrue(preg_match('/addVariable\\(\'alink1\',.*example.*/', $aMatch['script_content'][0]));
     // And target
     $this->assertTrue(strstr($aMatch['script_content'][0], "addVariable('atar1', '_blank')"));
 }
function renderOverlayInAdminTool($aOut, $aBanner)
{
    $title = "Overlay Preview";
    $borderStart = "<div style='color:black;text-decoration:none;border:1px solid black;padding:15px;'>";
    $borderEnd = "</div>";
    $htmlOverlay = '';
    switch ($aOut['overlayFormat']) {
        case VAST_OVERLAY_FORMAT_HTML:
            $htmlOverlay = $borderStart . $aOut['overlayMarkupTemplate'] . $borderEnd;
            break;
        case VAST_OVERLAY_FORMAT_IMAGE:
            $title = "Image Overlay Preview";
            $imagePath = getImageUrlFromFilename($aOut['overlayFilename']);
            $htmlOverlay = "<img border='0' src='{$imagePath}' />";
            break;
        case VAST_OVERLAY_FORMAT_SWF:
            $title = "SWF Overlay Preview";
            // we need to set a special state for adRenderFlash to work (which tie us to this implementation...)
            $aBanner['type'] = 'web';
            $aBanner['width'] = $aOut['overlayWidth'];
            $aBanner['height'] = $aOut['overlayHeight'];
            $htmlOverlay = _adRenderFlash($aBanner, $zoneId = 0, $source = '', $ct0 = '', $withText = false, $logClick = false, $logView = false);
            break;
        case VAST_OVERLAY_FORMAT_TEXT:
            $title = "Text Overlay Preview";
            $overlayTitle = $aOut['overlayTextTitle'];
            $overlayDescription = str_replace("\n", "<br/>", $aOut['overlayTextDescription']);
            $overlayCall = $aOut['overlayTextCall'];
            $htmlOverlay = "\n            \t{$borderStart}\n                    <div style='font-family:arial;font-size:18pt;font-weight:bold;'>{$overlayTitle} </div>\n                    <div style='font-family:arial;font-size:15pt;'>{$overlayDescription}</div>\n                    <div style='font-family:arial;font-size:15pt;font-weight:bold;color:orange;'>{$overlayCall}</div>\n                {$borderEnd}\n            ";
            break;
    }
    $htmlOverlayPrepend = 'The overlay will appear on top of video content during video play.';
    switch ($aOut['overlayFormat']) {
        case VAST_OVERLAY_FORMAT_IMAGE:
        case VAST_OVERLAY_FORMAT_SWF:
            $htmlOverlayPrepend .= " This overlay has the following dimensions: width = " . $aOut['overlayWidth'] . ", height = " . $aOut['overlayHeight'] . ".";
            break;
    }
    if ($aOut['overlayDestinationUrl']) {
        $htmlOverlayPrepend .= ' In the video player, this overlay will be clickable.';
        $htmlOverlay = "<a target=\"_blank\" href=\"{$aOut['overlayDestinationUrl']}\"> {$htmlOverlay}</a>";
    }
    $htmlOverlay = $htmlOverlayPrepend . '<br/><br/>' . $htmlOverlay;
    $player = "<h3>{$title}</h3>";
    $player .= $htmlOverlay;
    $player .= "<br>";
    return $player;
}