<?php
function Plugin_bannerTypeHtml_mobExpand_expandBanner_Delivery_adRender(&$aBanner, $zoneId=0, $source='', $ct0='', $withText=false, $logClick=true, $logView=true, $useAlt=false, $loc, $referer)
{
	$pagename = basename($_SERVER['PHP_SELF']);
	
	if($zoneId == 0)	
	{ 
	$conf = $GLOBALS['_MAX']['CONF'];
    $aBanner['bannerContent'] = $imageUrl = adRenderBuildFileUrl($aBanner, $useAlt);
    $prepend = (!empty($aBanner['prepend']) && $useAppend) ? $aBanner['prepend'] : '';
    $append = (!empty($aBanner['append']) && $useAppend) ? $aBanner['append'] : '';

    // Create the image tag..
    if (!empty($imageUrl)) {
        $imgStatus = empty($clickTag) && !empty($status) ? $status : '';
        $width = !empty($aBanner['width']) ? $aBanner['width'] : 0;
        $height = !empty($aBanner['height']) ? $aBanner['height'] : 0;
        $alt = !empty($aBanner['alt']) ? htmlspecialchars($aBanner['alt'], ENT_QUOTES) : '';
        $imageTag = "$clickTag<img src='".htmlspecialchars($imageUrl, ENT_QUOTES)."' width='$width' height='$height' alt='$alt' title='$alt' border='0'$imgStatus />$clickTagEnd";
    } else {
        $imageTag = '';
    }

    $bannerText = $withText && !empty($aBanner['bannertext']) ? "<br />$clickTag" . htmlspecialchars($aBanner['bannertext'], ENT_QUOTES) . "$clickTagEnd" : '';
     $beaconTag = ($logView && $conf['logging']['adImpressions']) ? _adRenderImageBeacon($aBanner, $zoneId, $source, $loc, $referer) : '';
    return $prepend . $imageTag . $bannerText . $beaconTag . $append;
	
	}
	else
	if($pagename != 'afr.php')
	{
		$conf = $GLOBALS['_MAX']['CONF'];
		$aBanner['bannerContent'] = $imageUrl = adRenderBuildFileUrl($aBanner, $useAlt);
		$aBanner['alt_contenttype'] = $alt_imageurl = adRenderBuildFileUrl($aBanner, true);
        
      // Create the image tag...
      
		if (!empty($imageUrl) && !empty($alt_imageurl)) {
        $imgStatus = empty($clickTag) && !empty($status) ? $status : '';
        $width = !empty($aBanner['width']) ? $aBanner['width'] : 0;
        $height = !empty($aBanner['height']) ? $aBanner['height'] : 0;
        $alt = !empty($aBanner['alt']) ? htmlspecialchars($aBanner['alt'], ENT_QUOTES) : '';
        $clickUrl = _adRenderBuildClickUrl($aBanner, $zoneId, $source, $ct0, $logClick);
        $LogUrl = _adRenderBuildLogUrl($aBanner, $zoneId, $source = '', $loc = '', $referer = '', $amp = '&amp;', $fallBack = false);
		if (!empty($clickUrl)) {  $status = _adRenderBuildStatusCode($aBanner);
		$clickTag = "<a href='".htmlspecialchars($clickUrl, ENT_QUOTES)."' target='{target}'$status>";
		$clickTagEnd = '</a>';
		} else {
		$clickTag = '';
		$clickTagEnd = '';
		}
		
		$dj_protocol = $GLOBALS['_MAX']['SSL_REQUEST'] ? "https://" : "http://" ;
    	$close_button = $dj_protocol.$conf['webpath']['admin'];
 
        $imageTag = "$clickTag<img  class='imgPic' src='".htmlspecialchars($imageUrl, ENT_QUOTES)."' width='$width' height='$height' alt='$alt' title='$alt' border='0'$imgStatus />$clickTagEnd";
		$imageTag_alt = "<img src='".htmlspecialchars($alt_imageurl, ENT_QUOTES)."' alt='$alt' title='$alt'  />";
		$content = '<style>
		.CdContent
		{
		display:inline-block;
		}
		#CdpopUp .CdpopUp
		{
		    position: fixed;
			width: 100%;
			height: 100%;
			background: rgba(0, 0, 0, 0.25);
			top: 0;
			left: 0;
		}
		
		#CdpopUp:not(.expand) .CdpopUp
		{
		    visibility: hidden;
		}
		
		#CdpopUp.expand .CdpopUp
		{
		      visibility: visible;
		      animation: 0.2s CdSlidein linear;
		      z-index: 10;
		}
		
		@keyframes CdSlidein 
		{
			from {
					background: rgba(0, 0, 0, 0.025);
				 }
			to {
					background: rgba(0, 0, 0, 0.25);
				}
		}

		#CdpopUp .CdpopUp-layout
		{
		    overflow: auto;
			height: 100%;
		}
		
		#CdpopUp .CdpopUp-content
		{
			margin: auto;
			top: 0;
			margin-top: 40px;
			margin-bottom: 40px;
			position: relative;
			transition:0.2s linear;
			max-width: calc(100% - 40px);
		}
		
		#CdpopUp .CdpopUp-content .imgPic
		{
		    max-width: 100%;
			height: auto;
		}
		
		#CdpopUp:not(.expand) .CdpopUp-content
		{
		   opacity:0;
		}
		
		#CdpopUp.expand .CdpopUp-content
		{
		    
		      opacity:1;
		}
		
		#CdpopUp  .cd_expand_close
		{
		    position: absolute;
			top: -15px;
			right: -15px;
			cursor:pointer;
    
		}
		
		#CdpopUp .Cd-base
		{
			transition:0.2s linear;
			cursor:pointer;
		}
		
		#CdpopUp.expand .Cd-base
		{
			transition:0s;
			opacity:0;
		} 
		
		#CdpopUp .Cd-base img
		{
		    max-width: 100%;
			height: auto;
		}
		
	</style>
		<div class="CdContent" id="CdpopUp">
			<div class="CdpopUp">
				<div class="CdpopUp-layout">
					<div class="CdpopUp-content" style="width:'.$width.'px;">
						<div class="cd_expand_close" onclick="this.closest(&apos;.CdContent&apos;).className = &apos;CdContent&apos;;" >
							<img  src="'.$close_button.'/plugins/ExpandBanner/images/close.png" >
						</div>'.$imageTag.'
					</div>
				</div>
			</div>
			<div  class="Cd-base"onclick="this.closest(&apos;.CdContent&apos;).className = &apos;CdContent expand&apos;;">'.$imageTag_alt.'</div>
			<img src="'.$LogUrl.'">
		</div>'; 

		return $content;
		
		} 
			
	}
	else
	{
		$content=""; 
		return  $content;
	}
}

if (!function_exists('adRenderBuildFileUrl')) 
 {
function adRenderBuildFileUrl($aBanner, $useAlt = false, $params = '')
{
		$aBanner['type'] = 'web';
		$conf = $GLOBALS['_MAX']['CONF'];
		$fileUrl = '';
   
        $fileName = $useAlt ? $aBanner['alt_filename'] : $aBanner['filename'];
        $params = !empty($params) ? $params : '';
        if (!empty($fileName)) {
                $fileUrl = _adRenderBuildImageUrlPrefix() . "/{$fileName}";
                if (!empty($params)) {
                    $fileUrl .= "?{$params}";
                }
        }
     
		return $fileUrl;
}
}

if (!function_exists('adRenderBuildImageUrlAdmin')) 
 {
function adRenderBuildImageUrlAdmin()
{
		$conf = $GLOBALS['_MAX']['CONF'];
		return $GLOBALS['_MAX']['SSL_REQUEST'] ? 'https://' . $conf['webpath']['imagesSSL'] : 'http://' .  $conf['webpath']['admin'];
}
}
